Pagini recente » Cod sursa (job #3157463) | Cod sursa (job #3255315) | Cod sursa (job #1578526) | Cod sursa (job #233276) | Cod sursa (job #1502870)
#include <cstdio>
#include <iomanip>
using namespace std;
FILE *f = fopen ( "royfloyd.in" , "r" ) , *g = fopen ( "royfloyd.out" , "w" );
const int MAX = 101 , INF = 200000000;
int i , j , k , N , cost[MAX][MAX];
void read()
{
fscanf ( f , "%d" , &N );
for ( i = 1; i <= N ; i ++ )
for ( j = 1; j <= N ; j ++ )
{
fscanf ( f , "%d" , &cost [ i ] [ j ] );
if ( cost [ i ] [ j ] == 0 && i != j ) cost [ i ] [ j ] = INF;
}
}
void solve()
{
for ( i = 1; i <= N ; i ++ )
for ( j = 1; j <= N ; j ++ )
for ( k = 1; k <= N ; k ++ )
if ( cost [ i ] [ k ] && cost [ k ] [ j ] && i != j )
cost [ i ] [ j ] = min ( cost [ i ] [ j ] , cost [ i ] [ k ] + cost [ k ] [ j ] );
}
void print()
{
for ( i = 1; i <= N ; i ++ )
{
for ( j = 1; j <= N ; j ++ )
fprintf ( g , "%d " , cost [ i ] [ j ] );
fprintf ( g , "\n" );
}
}
int main()
{
read();
solve();
print();
return 0;
}