Cod sursa(job #2824641)

Utilizator csoareCristian Soare csoare Data 2 ianuarie 2022 20:34:56
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.62 kb
#include <fstream>
#include <vector>
#include <limits>

int main() {
	std::ifstream fin("royfloyd.in");
	std::ofstream fout("royfloyd.out");

	int n;
	fin >> n;

	std::vector<std::vector<uint16_t>> dist(n, std::vector<uint16_t>(n, std::numeric_limits<uint16_t>::max()));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			fin >> dist[i][j];

	for (int k = 0; k < n; k++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				dist[i][j] = std::min<uint16_t>(dist[i][j], dist[i][k] + dist[k][j]);


	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)
			fout << dist[i][j] << " ";
		fout << std::endl;
	}
}