Pagini recente » Cod sursa (job #72702) | Cod sursa (job #3333475) | Borderou de evaluare (job #1430058) | Monitorul de evaluare | Cod sursa (job #3324082)
#include <bits/stdc++.h>
using namespace std;
ifstream f("royfloyd.in");
ofstream o("royfloyd.out");
int n;
int m[101][101];
int dist[101][101];
int main()
{
f>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
f>>m[i][j];
if(i==j)
dist[i][j]=0;
else{
if(m[i][j]!=0)
dist[i][j]=m[i][j];
else
dist[i][j]=1001;
}
}
}
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]>1000)
o<<0<<' ';
else
o<<dist[i][j]<<' ';
}
o<<'\n';
}
return 0;
}