Cod sursa(job #2966083)

Utilizator victor_gabrielVictor Tene victor_gabriel Data 16 ianuarie 2023 18:54:59
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>

using namespace std;

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

const int DIM = 110;
const int INF = 100001;

int n;
int a[DIM][DIM];

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

    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++) {
        for (int j = 1; j <= n; j++)
            fout << a[i][j] << ' ';
        fout << '\n';
    }

    return 0;
}