Pagini recente » Cod sursa (job #2803380) | Cod sursa (job #3284783)
#include <fstream>
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int a[101][101],n;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>a[i][j];
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++)
if(i!=k)
for(int j=1;j<=n;j++)
if(j!=k&&i!=j&&a[i][k]!=0&&a[k][j]!=0&&(a[i][j]==0||a[i][j]>a[i][k]+a[k][j]))
a[i][j]=a[i][k]+a[k][j];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<'\n';
}
return 0;
}