Cod sursa(job #1218776)

Utilizator ptquake10ptquake10 ptquake10 Data 12 august 2014 15:11:05
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;

int n;
long long c[101][101];

int main() {
	
	freopen("input.txt","r",stdin);
	//freopen("royfloyd.out", "w", stdout);

	cin >> n;
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= n; j++) {
		cin >> c[i][j];
		if (c[i][j] == 0) {
			c[i][j] = 0x7fffffff;
		}
	}
	
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= n; j++)
	for (int k = 1; k <= n; k++)
		if (i != j && i != k && k != j) {
			c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
		}
		
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= n; j++) {
		if (c[i][j] == 0x7fffffff) {
			c[i][j] = 0;
		}
	}
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cout << c[i][j] << " ";
		}
		cout << "\n";
	}
	
	return 0;
}