Cod sursa(job #2815051)

Utilizator HatersMcCristian Ioan HatersMc Data 9 decembrie 2021 00:48:54
Problema Floyd-Warshall/Roy-Floyd Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <fstream>

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

int main() {
    int a[101][101], n, b[101][101];
    f >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            f >> a[i][j];
            b[i][j] = a[i][j];
        }
        b[i][i] = 0;
    }
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < n; ++k)
                if(b[i][j]>b[i][k]+b[k][j])
                    b[i][j]=b[i][k]+b[k][j];

    for(int i = 0 ; i < n ;++i)
    {
        for(int j = 0 ; j < n ;++j)
            g<<b[i][j]<<" ";
        g<<'\n';
    }

                return 0;
}