Pagini recente » Clasament Teme ACM Unibuc 2013 | Cod sursa (job #186907) | Cod sursa (job #2579231) | Cod sursa (job #30825) | Cod sursa (job #3186489)
#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(a[i][j]>a[i][k]+a[k][j]||(a[i][j]==0&&i!=j))
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;
}