Cod sursa(job #2302775)

Utilizator RaresV227Virjoghe Rares Constantin RaresV227 Data 15 decembrie 2018 10:06:12
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <iostream>
#include <fstream>
#include <climits>

using namespace std;

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

int d[105][105], n;

void citire()
{
    f >> n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        {
            f >> d[i][j];
            if(d[i][j] == 0)
                d[i][j] == INT_MAX;
        }
}

void afisare()
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
            g << d[i][j] << ' ';
        g << '\n';
    }
}

int main()
{
    citire();
    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    afisare();


    return 0;
}