Pagini recente » Cod sursa (job #668704) | Cod sursa (job #2204716) | Cod sursa (job #2427753) | Cod sursa (job #2724457) | Cod sursa (job #2376586)
#include <bits/stdc++.h>
#define N 105
#define inf 200000000
using namespace std;
ifstream fin( "royfloyd.in" );
ofstream fout( "royfloyd.out" );
int n;
int cost[N][N];
void read()
{
int i, j;
fin >> n;
for ( i = 1; i <= n; ++i )
for ( j = 1; j <= n; ++j )
{
fin >> cost[i][j];
if ( cost[i][j] == 0 && i != j )
cost[i][j] = inf;
}
fin.close();
}
void roy_floyd()
{
int k, i, j;
for ( k = 1; k <= n; ++k )
for ( i = 1; i <= n; ++i )
for ( j = 1; j <= n; ++j )
if ( cost[i][j] > cost[i][k] + cost[k][j] )
cost[i][j] = cost[i][k] + cost[k][j];
}
void out()
{
int i, j;
for ( i = 1; i <= n; ++i )
{
for ( j = 1; j <= n; ++j )
if ( cost[i][j] != inf )
fout << cost[i][j] << ' ';
else fout << 0 << ' ';
fout << '\n';
}
}
int main()
{
read();
roy_floyd();
out();
fout.close();
return 0;
}