Cod sursa(job #2919504)

Utilizator OvidRata Ovidiu Ovid Data 17 august 2022 20:40:55
Problema Floyd-Warshall/Roy-Floyd Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.04 kb
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
//#define int ll


ifstream fin("royfloyd.in"); ofstream fout("royfloyd.out");
#define cin fin
#define cout fout

int adj[101][101];
int n;




int32_t main(){
INIT
cin>>n;
for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
        cin>>adj[i][j];
    }
}



for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
        for(int k=1; k<=n; k++){
            if( adj[i][j]==0 || adj[i][k]==0 || adj[j][k]==0){
                continue;
            }
            adj[i][j]=min(adj[i][k]+adj[k][j], adj[i][j]);
        }
    }
}

for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
        cout<<adj[i][j]<<" ";
    }
    cout<<"\n";
}


return 0;
}