Cod sursa(job #1022876)

Utilizator harababurelPuscas Sergiu harababurel Data 6 noiembrie 2013 08:14:03
Problema Floyd-Warshall/Roy-Floyd Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>
#define nmax 105
#define inf (1<<30)
using namespace std;

int n, w[nmax][nmax];

int main() {
	ifstream f("royfloyd.in");
	ofstream g("royfloyd.out");

	f>>n;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++) {
			f>>w[i][j];
			if(i!=j && w[i][j] == 0) w[i][j] = inf;
		}

	for(int k=1; k<=n; k++)
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				w[i][j] = min(w[i][j], w[i][k] + w[k][j]);

	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++)
			if(w[i][j]*10 < inf) g<<w[i][j]<<" ";
			else g<<"0 ";
		g<<"\n";
	}

	return 0;
}