Cod sursa(job #525768)

Utilizator unudoitreiRusu Alexandru unudoitrei Data 26 ianuarie 2011 09:54:03
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <iostream>
#include <fstream>

using namespace std;

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

ifstream fin(iname);
ofstream fout(oname);

int A[128][128], i, j, n, k, cost[128][128];

int main()
{
	fin >> n;
	for(i = 1; i <= n; i ++)
		for(j = 1; j <= n; j ++)
		{
			fin >> A[i][j];
			cost[i][j] = A[i][j];
			if(A[i][j] == 0)
				A[i][j] = 23232323;
		}
	
	for(k = 1; k <= n; k ++)
		for(i = 1; i <= n; i ++)
			for(j = 1; j <= n; j ++)
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			
	for(i = 1; i <= n; i ++)
	{
		for(j = 1; j <= n; j ++)
		{
			if(cost[i][j] == 23232323)
				fout << "0 ";
			else
				fout << cost[i][j] << " ";
		}
		fout << "\n";
	}
			
	return 0;
}