Pagini recente » Cod sursa (job #2939597) | Cod sursa (job #626781) | Cod sursa (job #3270126) | Cod sursa (job #1849999) | Cod sursa (job #2943103)
#include <stdio.h>
#include <vector>
#define NMAXX 100
using namespace std;
int mat[NMAXX][NMAXX];
int main() {
FILE *fin, *fout;
int n, l, c, i;
fin = fopen( "royfloyd.in", "r" );
fout = fopen( "royfloyd.out", "w" );
fscanf( fin, "%d", &n );
for ( l = 0; l < n; l++ )
for ( c = 0; c < n; c++ ) {
fscanf( fin, "%d", &mat[l][c] );
if ( mat[l][c] == 0 )
mat[l][c] = 100001;
}
for ( i = 0; i < n; i++ )
for ( l = 0; l < n; l++ )
for ( c = 0; c < n; c++ )
mat[l][c] = min( mat[l][c], mat[l][i] + mat[i][c] );
for ( l = 0; l < n; l++ ) {
for ( c = 0; c < n; c++ ) {
if ( l != c )
fprintf( fout, "%d ", mat[l][c] );
else
fprintf( fout, "0 " );
}
fputc( '\n', fout );
}
fclose( fin );
fclose( fout );
return 0;
}