Cod sursa(job #2851027)

Utilizator SlavicGGuzun Veaceslav SlavicG Data 17 februarie 2022 22:42:51
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 kb
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

void solve() {
    int n; cin >> n;
    vector<vector<ll>> dist(n, vector<ll>(n, (ll)1e16));

    forn(i, n) forn(j, n) cin >> dist[i][j];

    for(int k = 0;k < n; ++k) {
        for(int i = 0;i < n; ++i) {
            for(int j = 0;j < n; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    forn(i, n) {
        forn(j, n) cout << dist[i][j] << " ";
        cout << "\n";
    }
} 
 
int32_t main() {
    freopen("royfloyd.in", "r", stdin);
    freopen("royfloyd.out", "w", stdout);
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}