Cod sursa(job #3360233)

Utilizator pkseVlad Bondoc pkse Data 10 iulie 2026 19:04:07
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <bits/stdc++.h>
using namespace std;

ifstream f("royfloyd.in");
ofstream g("royfloyd.out");

const int nmax = 100;
const int inf = 1'000'000'000;

int dist[nmax][nmax];

int main() {
    int n; f >> n;
    for(int i = 0, j; i < n; i ++)
        for(j = 0; j < n; j ++)
            f >> dist[i][j],
            i != j && !dist[i][j] ? dist[i][j] = inf : 0;
    for(int i, j, k = 0; k < n; k ++)
        for(i = 0; i < n; i ++)
            for(j = 0; j < n; j ++)
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    for(int i = 0, j; i < n; i ++)
        for(j = 0; j < n; j ++)
            g << (dist[i][j] == inf ? 0 : dist[i][j]) << " \n"[j == n - 1];
}