Cod sursa(job #2277412)

Utilizator theoioanaTheodoraD theoioana Data 6 noiembrie 2018 10:34:41
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
#include <fstream>

#define INF 10000000

using namespace std;



int main(){



    ifstream cin("royfloyd.in");

    ofstream cout("royfloyd.out");



    int a[110][110];



    int n; cin >> n;



    for( int i = 0; i < n; i++){

        for( int j = 0; j < n; j++){

            cin >> a[i][j];

            if( a[i][j] == 0){

                a[i][j] = INF;

            }

        }

    }



    for( int k = 0; k < n; k++){

        for( int i = 0; i < n; i++){

            for( int j = 0; j < n; j++){

                if( i != j && a[i][j] > a[i][k] + a[k][j] ){

                    a[i][j] = a[i][k] + a[k][j];

                }

            }

        }

    }



    for( int i = 0; i < n; i++){

        for( int j = 0; j < n; j++){

            if( a[i][j] == INF)

                cout << 0 << " ";

            else

                cout << a[i][j] << " ";

        }

        cout << '\n';

    }



    return 0;

}