Pagini recente » oni_clasa_9 | Cod sursa (job #2814344) | Cod sursa (job #1130963)
//#include <iostream>
#include<fstream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
#define maxn 101
int a,b,m,n,v[maxn][maxn],i,j,k;
int main()
{
cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
cin>>v[i][j];
}
}
for(k=1;k<=n;k++){
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(i==j || !v[i][k] || !v[k][j]){
continue;
}
if(v[i][j]==0){
v[i][j]=v[i][k]+v[k][j];
}else{
v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
}
}
}
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
cout<<v[i][j]<<' ';
}
cout<<'\n';
}
return 0;
}