Cod sursa(job #3321933)

Utilizator g.vladGociu Vlad g.vlad Data 11 noiembrie 2025 19:37:22
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.88 kb

#include <fstream>

std::ifstream in("royfloyd.in");
std::ofstream out("royfloyd.out");

typedef unsigned short node_t;

using std::min;

int main() {
    node_t N;

    in >> N;

    node_t graph[100][100];
    node_t dist[100][100];

    for(node_t a = 0; a < N; a += 1) {
        for(node_t b = 0; b < N; b += 1) {
            in >> graph[a][b];
            dist[a][b] = graph[a][b] ? graph[a][b] : 2000;
        }
    }

    for(node_t mid = 0; mid < N; mid += 1) {
        for(node_t a = 0; a < N; a += 1) {
            for(node_t b = 0; b < N; b += 1) {
                dist[a][b] = min<node_t>(dist[a][b],  dist[a][mid] + dist[mid][b]);
            }
        }
    }

    for(node_t a = 0; a < N; a += 1) {
        for(node_t b = 0; b < N; b += 1) {
            out << ( dist[a][b] * (dist[a][b] != 2000) ) << ' ';
        }
        out << '\n';
    }
}