Cod sursa(job #1579730)

Utilizator lflorin29Florin Laiu lflorin29 Data 25 ianuarie 2016 00:30:25
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>

using namespace std;

const int N = 128;

int n;
int a[N][N];

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

    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            scanf("%d", &a[i][j]);
    for(int act = 1; act <= n; ++act)
        for(int i = 1; i <= n; ++i)
           for(int j = 1; j <= n; ++j)
               if(i != j and a[i][j] and a[act][j] and a[i][act])
                  a[i][j] = min(a[i][j], a[act][j] + a[i][act]);

    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j)
            printf("%d ", a[i][j]);
        printf("\n");
    }
    return 0;
}