Cod sursa(job #2964880)

Utilizator Iordache_CezarIordache Cezar Iordache_Cezar Data 14 ianuarie 2023 09:24:24
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <fstream>
#define INF 1e9
#define NMAX 300

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

int n, c[NMAX][NMAX];

int main()
{
    fin >> n;

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            fin >> c[i][j];
            if (c[i][j] == 0)
                c[i][j] = INF;
        }
        c[i][i] = 0;
    }

    for (int z = 1; z <= n; z++)
        for (int x = 1; x <= n; x++)
            for (int y = 1; y <= n; y++)
                c[x][y] = min(c[x][y], c[x][z] + c[z][y]);

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1;j <= n; j++)
            fout << c[i][j] << ' ';
        fout << '\n';
    }
    return 0;
}