Cod sursa(job #2972269)

Utilizator sanzianagrecuSanziana Grecu sanzianagrecu Data 28 ianuarie 2023 22:35:40
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <fstream>

using namespace std;

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

#define NMAX 101
#define INF 0x3f3f3f3f

int n, a[NMAX][NMAX];

int main() {

    fin >> n;

    for (int i = 1; i <= n; ++ i)
        for (int j = 1; j <= n; ++ j)
            fin >> a[i][j];

    for (int k = 1; k <= n; ++ k)
        for (int i = 1; i <= n; ++ i)
            for (int j = 1; j <= n; ++ j)
                if (a[i][j] > a[i][k] + a[k][j])
                    a[i][j] = a[i][k] + a[k][j];

    for (int i = 1; i <= n; ++ i, fout << '\n')
        for (int j = 1; j <= n; ++ j)
            fout << a[i][j] << ' ';


    return 0;
}