Pagini recente » Cod sursa (job #2213003) | Cod sursa (job #2982514) | Cod sursa (job #2437769) | Cod sursa (job #2437959) | Cod sursa (job #3186491)
#include <fstream>
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int n,i,j,k,a[101][101];
int main()
{
cin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
cin>>a[i][j];
for(k=1;k<=n;k++) // consideram nodul k ca fiind nodul intermediar dintre nodul i si nodul j
for(i=1;i<=n;i++)
for(j=1;j<=n;j++){
if(i!=j&&a[i][k]!=0&&a[k][j]&&(a[i][j]>a[i][k]+a[k][j]||a[i][j]==0))
a[i][j]=a[i][k]+a[k][j];
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<'\n';
}
return 0;
}