Cod sursa(job #2907276)

Utilizator Apyxabcdefghij Apyx Data 29 mai 2022 15:06:55
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <bits/stdc++.h>
#define nmax 100

using namespace std;

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

int dist[nmax+5][nmax+5];

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