Cod sursa(job #2499513)

Utilizator CiboAndreiAndrei Cibo CiboAndrei Data 26 noiembrie 2019 11:45:22
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 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, a, b, x, j;

    f >> n;

    for(i = 1; i <= n; ++i)
        fill_n(dist[i], n, oo);

    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)
                dist[i][j] = min(dist[i][j], dist[i][x] + dist[x][j]);

    for(i = 1; i <= n; ++i, g << '\n')
        for(j = 1; j <= n; g << ((i != j && dist[i][j] != oo) ? dist[i][j] : 0) << " ", ++j);

    return 0;
}