Pagini recente » Cod sursa (job #971382) | Cod sursa (job #2838064)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int MAX=105;
const int INF=1e9;
int n,dist[MAX][MAX];
int main()
{
fin >> n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
fin >> dist[i][j];
if(dist[i][j]==0 && i!=j)
dist[i][j]==INF;
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(dist[i][j]>dist[i][k]+dist[k][j])
dist[i][j]=dist[i][k]+dist[k][j];
for(int i=1;i<=n;i++, fout << '\n')
for(int j=1;j<=n;j++)
if(dist[i][j]==INF)
fout << "0 ";
else
fout << dist[i][j] << " ";
return 0;
}