Pagini recente » Cod sursa (job #1409060) | Cod sursa (job #385841) | Cod sursa (job #2620026) | Cod sursa (job #1004929) | Cod sursa (job #2840496)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int cost[101][101];
int n;
int main()
{
fin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
fin>>cost[i][j];
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j && cost[i][k]*cost[k][j]!=0 &&
(cost[i][j]>cost[i][k]+cost[k][j] || cost[i][j]==0))
cost[i][j]=cost[i][k]+cost[k][j];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
fout<<cost[i][j]<<' ';
fout<<'\n';
}
return 0;
}