Cod sursa(job #1794691)

Utilizator FlowstaticBejan Irina Flowstatic Data 1 noiembrie 2016 17:16:29
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <fstream>
#define NMAX 105
#define FOR(i, a, b) for( int i = a; i <= b; i++)
using namespace std;

ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");

int N;
int a[NMAX][NMAX];

int main()
{
    fin>>N;
    FOR(i,1,N)
        FOR(j,1,N)
            fin>>a[i][j];

    FOR(k,1,N)
        FOR(i,1,N)
            FOR(j,1,N)
                if((!a[i][j] || a[i][j] > a[i][k] + a[k][j]) && i!=j && a[i][k] && a[k][j])
                    a[i][j] = a[i][k]+a[k][j];

    FOR(i,1,N)
    {
        FOR(j,1,N)
            fout<<a[i][j]<<" ";
        fout<<'\n';
    }
    return 0;
}