Cod sursa(job #2861632)

Utilizator Xutzu358Ignat Alex Xutzu358 Data 4 martie 2022 10:29:35
Problema Floyd-Warshall/Roy-Floyd Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <bits/stdc++.h>
#define oo 2000000001
using namespace std;

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

int n;
int dist[105][105];
int muchii[105][105];

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

void roy_floyd() {
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=n;j++) {
            for (int k=1;k<=n;k++) {
                dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
}

void show() {
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=n;j++) {
            g << dist[i][j] << " ";
        }
        g << '\n';
    }
}

int main()
{
    read();
    roy_floyd();
    show();
    return 0;
}