Mai intai trebuie sa te autentifici.
Cod sursa(job #2080671)
Utilizator | Data | 3 decembrie 2017 13:48:59 | |
---|---|---|---|
Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.76 kb |
#include<iostream>
#include<fstream>
using namespace std;
#define maxConst 100
int weight[maxConst][maxConst];
int main() {
ifstream inFile("royfloyd.in");
ofstream outFile("royfloyd.out");
int n, i, j, k;
inFile >> n;
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
inFile >> weight[i][j];
}
}
for (k = 0; k < n; ++k) {
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
if (i != j && weight[i][k] != 0 && weight[k][j] !=0 && weight[i][j] > weight[i][k] + weight[k][j]) {
weight[i][j] = weight[i][k] + weight[k][j];
}
}
}
}
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
outFile << weight[i][j] << " ";
}
outFile << "\n";
}
inFile.close();
outFile.close();
return 0;
}