Cod sursa(job #2427360)

Utilizator ToniBAntonia Biro ToniB Data 31 mai 2019 17:16:47
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream in("grader_test2.in");
ofstream out("royfloyd.out");

#define INF 1000

int d[100][100];

int main()
{
    if(!in)
    {
        cout << "eroare";
        return -1;
    }
    int n;
    in >> n;

    for(int i = 0; i < n; ++i)
        for(int j = 0;j < n; ++j)
        {
            int x;
            in >> x;
            if(i != j && x == 0)
                d[i][j] = INF;
            else
                d[i][j] = x;
        }
    for(int k = 0; k < n; ++k)
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                if(d[i][j] > d[i][k] + d[k][j])
                    d[i][j] = d[i][k] + d[k][j];
    for(int i = 0; i < n; ++i)
   {
       for(int j = 0; j < n; ++j)
            out << d[i][j] << ' ';
        out << '\n';
    }

    in.close();
    out.close();
}