Cod sursa(job #3349902)

Utilizator coco11coraline kalbfleisch coco11 Data 3 aprilie 2026 10:35:51
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    freopen("royfloyd.in","r",stdin);
    freopen("royfloyd.out","w",stdout);
    int N;cin>>N;
    int inf=10000;
    int dist[N][N];
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>dist[i][j];
            if(dist[i][j]==0){
                dist[i][j]=inf;
            }
        }
    }
    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]);
            }
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(dist[i][j]==inf || (i==j))dist[i][j]=0;
            cout<<dist[i][j]<<" ";
        }
        cout<<'\n';
    }
}