Cod sursa(job #2499521)

Utilizator CiboAndreiAndrei Cibo CiboAndrei Data 26 noiembrie 2019 11:51:58
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <bits/stdc++.h>

using namespace std;

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

const int dim = 101;
const int oo = INT_MAX / 2;

int n, m;
int dist[dim][dim];

int main()
{
    int i, x, j;

    f >> n;

    for(i = 1; i <= n; ++i)
        for(j = 1; j <= n; ++j)
            f >> dist[i][j];

    for(x = 1; x <= n; ++x)
        for(i = 1; i <= n; ++i)
            for(j = 1; j <= n; ++j)
                if(dist[i][x] != 0 && dist[x][j] != 0 && i != j && (dist[i][j] > dist[i][x] + dist[x][j] || dist[i][j] == 0))
                    dist[i][j] = dist[i][x] + dist[x][j];

    for(i = 1; i <= n; ++i, g << '\n')
        for(j = 1; j <= n; g << dist[i][j] << " ", ++j);

    return 0;
}