Pagini recente » Cod sursa (job #946417) | Cod sursa (job #519044) | Cod sursa (job #865991) | Cod sursa (job #1083820) | Cod sursa (job #3251485)
#include <bits/stdc++.h>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int n, dist[1001][1001];
int inf=10000000;
int main()
{ in>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
in>>dist[i][j];
if(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++){
if(i!=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<<endl;
}
return 0;
}