Pagini recente » Statisticile problemei Cars | Cod sursa (job #1999569) | Cod sursa (job #9764) | Cod sursa (job #3136346) | Cod sursa (job #3200745)
#include <fstream>
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int n;
long long costuri[101][101];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>costuri[i][j];
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(costuri[i][k] && costuri[k][j])
{
int new_cost=costuri[i][k]+costuri[k][j];
if((!costuri[i][j] && i!=j) || new_cost<costuri[i][j])
costuri[i][j]=new_cost;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<costuri[i][j]<<" ";
cout<<'\n';
}
return 0;
}