Mai intai trebuie sa te autentifici.
Cod sursa(job #1456527)
| Utilizator | Data | 1 iulie 2015 08:36:41 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.74 kb |
#include <fstream>
using namespace std;
int main(int argc, char **argv)
{
ifstream indata("royfloyd.in");
// input data
int n;
indata >> n;
int cost_mat[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
indata >> cost_mat[i][j];
}
}
// apply Roy-Floyd to find shortestPath
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(cost_mat[i][j] > cost_mat[i][k] + cost_mat[k][j])
cost_mat[i][j] = cost_mat[i][k] + cost_mat[k][j];
}
}
}
// output data
ofstream outdata("royfloyd.out");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
outdata << cost_mat[i][j] << " ";
}
outdata << "\n";
}
indata.close();
outdata.close();
return 0;
}
