Pagini recente » Cod sursa (job #2696146) | Cod sursa (job #182708) | Cod sursa (job #3278603) | Cod sursa (job #2424120) | Cod sursa (job #3233642)
#include <bits/stdc++.h>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
const int inf = 1e8+7;
int dist[105][105];
int n;
int main() {
in>>n;
for(int i=1;i<=n;++i) {
for(int j=1;j<=n;++j) {
in>>dist[i][j];
if(i!=j and dist[i][j] == 0) {
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) {
for(int j=1;j<=n;++j) {
if(dist[i][j] >= inf) {
out<<0<<' ';
} else {
out<<dist[i][j]<<' ';
}
}
out<<'\n';
}
return 0;
}