Cod sursa(job #1770447)

Utilizator Theodor1000Cristea Theodor Stefan Theodor1000 Data 4 octombrie 2016 14:07:43
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <cstdio>
#include <algorithm>

using namespace std;

int dist[128][128];

int main ()
{
    freopen ("royfloyd.in", "r", stdin);
    freopen ("royfloyd.out", "w", stdout);

    int n;
    scanf ("%d", &n);

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            scanf ("%d", &dist[i][j]);

    for (int h = 1; h <= n; ++h)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j)
                dist[i][j] = min (dist[i][j], dist[i][h] + dist[h][j]);

    for (int i = 1; i <= n; ++i, printf ("\n"))
        for (int j = 1; j <= n; ++j)
            printf ("%d ", dist[i][j]);

    return 0;
}