Cod sursa(job #3217727)

Utilizator DobraVictorDobra Victor Ioan DobraVictor Data 24 martie 2024 14:28:43
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <stdint.h>

int32_t min(int32_t x, int32_t y) {
	return (x < y) ? x : y;
}

const int32_t MAX_N = 100;
const int32_t MAX_VAL = 1000000;

int32_t dist[MAX_N][MAX_N];
int main() {
	std::ifstream fin("royfloyd.in");
	std::ofstream fout("royfloyd.out");

	int32_t n;
	fin >> n;

	for(int32_t i = 0; i != n; ++i)
		for(int32_t j = 0; j != n; ++j)
			fin >> dist[i][j];
	
	for(int32_t k = 0; k != n; ++k) {
		for(int32_t i = 0; i != n; ++i) {
			for(int32_t j = 0; j != n; ++j) {
				if(!dist[i][j] || !dist[i][k] || !dist[k][j])
					continue;
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	
	for(int32_t i = 0; i != n; ++i) {
		for(int32_t j = 0; j != n; ++j)
			fout << dist[i][j] << ' ';
		fout << '\n';
	}

	fin.close();
	fout.close();

	return 0;
}