Pagini recente » Arhiva de probleme | Cod sursa (job #1309989) | Monitorul de evaluare | Cod sursa (job #2835944) | Cod sursa (job #2084448)
#include <fstream>
#define INF 9999
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n,cost[105][105],i,j,k;
int main()
{
fin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
fin>>cost[i][j];
if(!cost[i][j])
cost[i][j]=INF;
}
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][k]!=INF && cost[k][j]!=INF)
if(cost[i][j]>cost[i][k]+cost[k][j] && i!=j)
cost[i][j]=cost[i][k]+cost[k][j];
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(cost[i][j]==INF)
fout<<0<<' ';
else
fout<<cost[i][j]<<' ';
}
fout<<'\n';
}
return 0;
}