Cod sursa(job #3360423)

Utilizator chisianisChis Ianis-Alexandru chisianis Data 13 iulie 2026 17:14:47
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

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

int adj[110][110];

int main()
{
    FASTIO
    
    int n; fin >> n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            fin >> adj[i][j];
    vector<vector<int>> dist(n + 1, vector<int>(n + 1, 1e9));
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            dist[i][j] = adj[i][j];
    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++)
            fout << dist[i][j] << ' ';
        fout << '\n';
    }
        
    return 0;
}