Pagini recente » Cod sursa (job #2275241) | Istoria paginii runda/simulare-cartita-22 | Cod sursa (job #1044748) | Rating Diana Serbu (mazens) | Cod sursa (job #2947876)
#include <stdio.h>
#define N 100
#define INF 100001
int cost[N][N], m[N][N];
int n;
int main() {
FILE *fin, *fout;
fin = fopen( "royfloyd.in", "r" );
fscanf( fin, "%d", &n );
for ( int i = 0; i < n; i ++ )
for ( int j = 0; j < n; j ++ ) {
fscanf( fin, "%d", &cost[i][j] );
}
fclose( fin );
for ( int k = 0; k < n; k ++ )
for ( int i = 0; i < n; i ++ )
for ( int j = 0; j < n; j ++ )
if ( cost[i][k] + cost[k][j] < cost[i][j] )
cost[i][j] = cost[i][k] + cost[k][j];
fout = fopen( "royfloyd.out", "w" );
for ( int i = 0; i < n; i ++ ) {
for ( int j = 0; j < n; j ++ ) {
fprintf( fout, "%d ", cost[i][j] );
}
fprintf( fout, "\n" );
}
fclose( fout );
return 0;
}