Pagini recente » Cod sursa (job #2330220) | Cod sursa (job #2870163) | Cod sursa (job #673086) | Cod sursa (job #242482) | Cod sursa (job #3298349)
#include <fstream>
#include <bits/stdc++.h>
const int inf=0x3f3f3f3f;
using namespace std;
int cost[105][105];
int main()
{
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n,a;
fin>>n;
memset(cost,inf,sizeof(cost));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
fin>>a;
if(a)
cost[i][j]=a;
}
cost[i][i]=0;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
if(i!=k)
cost[i][j]=min(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]*!(cost[i][j]==inf)<<" ";
}
fout<<'\n';
}
return 0;
}