Cod sursa(job #1528111)

Utilizator whoiscrisCristian Plop whoiscris Data 19 noiembrie 2015 02:08:30
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

typedef long long int ll;

#define REP(i, a, b) \
	for (int i=int(a); i<=int(b); ++i)

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


#define N 101
#define INF 10000

int G[N][N];
int n;

void read() {
	f >> n;
	REP (i, 1, n)
		REP (j, 1, n)
			f >> G[i][j];
}

void royfloyd() {
	int dist[N][N];

	REP (i, 1, n)
		REP (j, 1, n)
			if (i == j)
				dist[i][j] = 0;
			else if (G[i][j] == 0)
				dist[i][j] = INF;
			else
				dist[i][j] = G[i][j];

	REP (k, 1, n)
		REP (i, 1, n)
			REP (j, 1, n)
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

	REP (i, 1, n) {
		REP (j, 1, n)
			g << dist[i][j] << " ";
		g << endl;
	}
}


int main () {

	read();
	royfloyd();

	return 0;
}