Cod sursa(job #2694011)

Utilizator QubeeStefan Ste Qubee Data 7 ianuarie 2021 20:21:46
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

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

int G[101][101], n, m;

int main(){

    int x,y,z;
    f>> n;

    for(int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++){
            f>> x;
            if (x == 0 && i != j)
                G[i][j] = 1e9;
            else G[i][j] = x;
        }

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

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++)
            if (G[i][j] == 1e9) g << "0 ";
            else g<< G[i][j] << " ";

        g <<endl;

    }
    return 0;

}