Cod sursa(job #2682404)

Utilizator robertnanu_fmiNanu Robert-Ionut robertnanu_fmi Data 8 decembrie 2020 17:00:54
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("royfloyd.in");
ofstream g("royfloyd.out");

const int nmax = 1e2 + 1;
const int inf = 10000000;

int n, rin[nmax][nmax];

int main()
{
    f >> n;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            if (i!=j) rin[i][j]=inf;
                 else rin[i][j]=0;

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            f >> rin[i][j];

    for(int k = 1; k <= n; ++k)
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                rin[i][j] = min(rin[i][k] + rin[k][j], rin[i][j]);

    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
            if(rin[i][j] != inf) g<<rin[i][j]<<' ';
                        else g<<"-1 ";
        g<<'\n';
    }
    return 0;
}