Cod sursa(job #631201)

Utilizator NikitaUtiuNichita Utiu NikitaUtiu Data 7 noiembrie 2011 12:32:37
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <cstdio>
#include <algorithm>
using namespace std;

int cost[101][101];

int main (void) {
	int n;
	freopen("royfloyd.in", "r", stdin);
	freopen("royfloyd.out", "w", stdout);
	
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < n; ++j) {
			scanf("%d", &cost[i][j]);
			if(cost[i][j] == 0 && i != j)
				cost[i][j] = 999999;
		}
	
	for(int k = 0; k < n; ++k)
		for(int i = 0; i < n; ++i)
			for(int j = 0; j < n; ++j)
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
	
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j)
			printf("%d ", cost[i][j] * (cost[i][j] != 0));
		printf("\n");
	}
}