Cod sursa(job #2870764)

Utilizator 100pCiornei Stefan 100p Data 12 martie 2022 15:49:16
Problema Floyd-Warshall/Roy-Floyd Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.97 kb

#include <bits/stdc++.h>
#define FILES freopen("royfloyd.in","r",stdin);\
              freopen("royfloyd.out","w",stdout);
#define ll long long
#define fastio ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL);
#define MAX 100
#define pb push_back
#define mp make_pair
#define mod 666013
using namespace std;
int n,a,cost[MAX+5][MAX+5], dp[MAX+5][MAX+5];
int main()
{
    fastio
    FILES
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
        {
            cin >> cost[i][j];
            if(!cost[i][j] && i != j) cost[i][j] = 1e9;
        }
    }
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
        {
            for(int k = 1; k <= n; ++k)
                cost[j][i] = min(cost[j][i],cost[j][k] + cost[k][i]);
        }
    }
    for(int i = 1; i <= n; ++i,cout << '\n')
        for(int j = 1; j <= n; ++j)
            cout << (cost[i][j] == 1e9 ? 0 : cost[i][j]) << ' ';
}