Cod sursa(job #2686869)

Utilizator SochuDarabaneanu Liviu Eugen Sochu Data 19 decembrie 2020 13:46:27
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <bits/stdc++.h>
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define FILES freopen("royfloyd.in" , "r" , stdin) , freopen("royfloyd.out" , "w" , stdout)

using namespace std;

const int N = 105;

int n;
int a[N][N] , d[N][N];

signed main()
{
	#ifndef ONLINE_JUDGE
		FastIO , FILES;
	#endif

    int k , i , j;

    cin >> n;

    for(i = 1 ; i <= n ; i++)
        for(j = 1 ; j <= n ; j++)
            cin >> a[i][j] , d[i][j] = a[i][j];

    for(k = 1 ; k <= n ; k++)
        for(i = 1 ; i <= n ; i++)
            for(j = 1 ; j <= n ; j++)
                if(d[i][k] && d[k][j])
                    d[i][j] = min((!d[i][j] ? INT_MAX : d[i][j]) , d[i][k] + d[k][j]);

    for(i = 1 ; i <= n ; i++)
        for(j = 1 ; j <= n ; j++)
            cout << d[i][j] << " \n" [j == n];

    return 0;
}