Cod sursa(job #570088)

Utilizator pykhNeagoe Alexandru pykh Data 2 aprilie 2011 15:43:10
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include<cstdio>
using namespace std;

const char in[] = "royfloyd.in";
const char out[] = "royfloyd.out";

const int N_Max = 105;

inline int min(int a, int b){return (a > b ? b : a);}

int N, a[N_Max][N_Max];

int main()
	{
		freopen(in,"r",stdin);
		freopen(out,"w",stdout);
		scanf("%d", &N);
		for(int i = 1 ; i <= N ; ++i)
			for(int j = 1 ; j <= N ; ++j)
				scanf("%d", &a[i][j]);
		
		for(int k = 1 ; k <= N ; ++k)
			for(int i = 1 ; i <= N ; ++i)
				for(int j = 1 ; j <= N ; ++j)
					if(a[i][k] && a[k][j] && i != j)a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
			
		for(int i = 1 ; i <= N ; ++i){
			for(int j = 1 ; j <= N ; ++j)
				printf("%d ", a[i][j]);
			printf("\n");
		}
		return 0;
}