Cod sursa(job #1443828)

Utilizator Burbon13Burbon13 Burbon13 Data 28 mai 2015 18:27:09
Problema Floyd-Warshall/Roy-Floyd Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <iostream>
#include <cstdio>
using namespace std;

const int nmx = 105;

int n, mat[nmx][nmx];

inline void citire(){
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            scanf("%d", &mat[i][j]);
}

inline void calcul(){
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            for(int k = 1; k <= n; ++k)
            if(i != j &&mat[i][k] && mat[k][j] && (not mat[i][j] || mat[i][j] > mat[i][k] + mat[k][j] ))
                mat[i][j] = mat[i][k] + mat[k][j];
}

inline void afish(){
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j)
            printf("%d ", mat[i][j]);
        printf("\n");
    }
}

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

    citire();
    calcul();
    afish();
    return 0;
}