Cod sursa(job #2670897)

Utilizator davidcotigacotiga david davidcotiga Data 10 noiembrie 2020 21:38:17
Problema Floyd-Warshall/Roy-Floyd Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <stack>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <map>

#define INF (1 << 31) - 1;

using namespace std;

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


int main() {
	int n;
	int G[105][105];

	fin >> n;

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			fin >> G[i][j];

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (!G[i][j] && i != j)
				G[i][j] = INF;

	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				if (G[i][j] > G[i][k] + G[k][j])
					G[i][j] = G[i][k] + G[k][j];

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j)
			fout << G[i][j] << " ";
		fout << "\n";
	}

	return 0;
}