Cod sursa(job #1153383)

Utilizator irimiecIrimie Catalin irimiec Data 25 martie 2014 13:51:29
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>
#include <cstring>
#define INF 0x3f

using namespace std;

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

int n, in[101][101], dist[101][101];

int main()
{
	f >> n;
	
	for(int i = 1; i <= n; ++i)
	{
		dist[i][i] = 0;
		for(int j = 1; j <= n; ++j)
			f >> in[i][j], dist[i][j] = in[i][j];
	}	
	
	for(int k = 1; k <= n; ++k)
		for(int i = 1; i <= n; ++i)
			for(int j = 1; j <= n; ++j)
				if(i != j)
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j <= n; ++j)
			g << dist[i][j] << " ";
		g << '\n';
	}
}