Cod sursa(job #3376854)

Utilizator Nicolescu_RaduNicolescu Radu Mihai Nicolescu_Radu Data 20 noiembrie 2026 08:44:46
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
const int NMAX = 100;

int dist[NMAX+1][NMAX+1];

int main(){

    int n;
    f>>n;
    for(int i=1;i<=n;i++)
        for(int j =1; j<=n; j++){
            f>>dist[i][j];
            if(i!=j && dist[i][j] == 0){
                dist[i][j] = 1e9;
            }
        }

    for (int k = 1; k<=n; k++)
        for(int i=1; i<=n; i++)
            for(int j = 1; j<=n; j++){
                if(dist[i][j] > dist[i][k] + dist[k][j]){
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }

for(int i = 1;i<=n;i++){
    for(int j = 1; j<= n; j++){
        if(dist[i][j] == 1e9) g<<0<<" ";
        else g<<dist[i][j]<<" ";
    }
    g<<"\n";
}


    return 0;
}