Pagini recente » Cod sursa (job #846818) | Cod sursa (job #2320876) | Cod sursa (job #1535355) | Cod sursa (job #490114) | Cod sursa (job #3251497)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
long long dist[1005][1005];
int main()
{
fin>>n;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
int x;
fin>>x;
if(x==0) x=INT_MAX;
dist[i][j]=x;
}
}
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]==INT_MAX) fout<<0<<' ';
else fout<<dist[i][j]<<' ';
}
fout<<'\n';
}
return 0;
}