Cod sursa(job #3251471)

Utilizator IleaIlea Bogdan Ilea Data 26 octombrie 2024 09:19:03
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>

using namespace std;

string file="royfloyd";
ifstream fin(file+".in");
ofstream fout(file+".out");

int dist[1001][1001];
void royfloyd(int n)
{
    for (int k=1; k<=n; k++){
        for (int i=1; i<=n; i++){
            for (int j=1; j<=n; j++){
                dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }
}
int main()
{
    int n;
    fin>>n;
    for (int i=1; i<=n; i++){
        for (int j=1; j<=n; j++){
            fin>>dist[i][j];
        }
    }
    royfloyd(n);
    for (int i=1; i<=n; i++){
        for (int j=1; j<=n; j++){
            fout<<dist[i][j]<<" ";
        }
        fout<<"\n";
    }
    return 0;
}