Pagini recente » Cod sursa (job #521365) | Cod sursa (job #101417) | Cod sursa (job #64595) | Cod sursa (job #2541655) | Cod sursa (job #2981213)
#include <bits/stdc++.h>
#define nmax 100
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int inf = 0x3f3f3f3f;
int dist[nmax+5][nmax+5];
int main() {
ios::sync_with_stdio(false);
fin.tie(nullptr);
fout.tie(nullptr);
int n; fin >> n;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
fin >> dist[i][j];
if(!dist[i][j] && i != j) {
dist[i][j] = inf;
}
}
}
for(int k = 1; k <= n; k++) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
for(int i = 1; i <= n; i++, fout << "\n") {
for(int j = 1; j <= n; j++) {
if(dist[i][j] == inf) {
fout << 0 << " ";
} else {
fout << dist[i][j] << " ";
}
}
}
return 0;
}