Pagini recente » Cod sursa (job #2199887) | Cod sursa (job #3291862) | Cod sursa (job #712578) | Cod sursa (job #1103395) | Cod sursa (job #2374105)
# include <fstream>
# define DIM 105
# define INF 1000000000
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int v[DIM][DIM],n,m,k,i,j;
int main () {
fin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
fin>>v[i][j];
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(v[i][j]==0)
v[i][j]=INF;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i!=j&&i!=k&&j!=k&&v[i][j]>v[i][k]+v[k][j])
v[i][j]=v[i][k]+v[k][j];
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(v[i][j]==INF)
v[i][j]=0;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)
fout<<v[i][j]<<" ";
fout<<"\n";
}
return 0;
}