Cod sursa(job #3322491)

Utilizator GoreaRaresGorea Rares-Andrei GoreaRares Data 14 noiembrie 2025 14:30:18
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");

int n, a[101][101], dist[101][101];

void read(){
    fin >> n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            fin >> a[i][j], dist[i][j] = a[i][j];
}

void solve(){
    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                if(j != i)
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++)
            fout << dist[i][j] << " ";
        fout << "\n";
    }
}

int main()
{
    read();
    solve();
    return 0;
}