Cod sursa(job #2943103)

Utilizator teodorescunicolasteodorescu nicolas alexandru teodorescunicolas Data 20 noiembrie 2022 16:20:39
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb
#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;
}