Cod sursa(job #631200)

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

int cost[100][100];

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]);
	
	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]);
		printf("\n");
	}
}