Pagini recente » Cod sursa (job #2524999) | Cod sursa (job #2701505) | Cod sursa (job #748280) | Cod sursa (job #3226173) | Cod sursa (job #1969783)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");
const int maxn = 105;
const int oo = 1 << 30;
int G[maxn][maxn];
int n;
int main() {
ios_base :: sync_with_stdio(false);
fin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
fin >> G[i][j];
if (G[i][j] == 0 && i != j) G[i][j] = oo;
}
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (G[i][k] + G[k][j] < G[i][j]) G[i][j] = G[i][k] + G[k][j];
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (G[i][j] == oo) G[i][j] = 0;
fout << G[i][j] << " ";
}
fout << "\n";
}
return 0;
}