Cod sursa(job #2870772)

Utilizator 100pCiornei Stefan 100p Data 12 martie 2022 15:52:01
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 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 k = 1;k <= n; ++k)
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
                cost[i][j] = min(cost[i][j],cost[k][j] + cost[i][k]);
    }
    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]) << ' ';
}