Cod sursa(job #689544)

Utilizator tvararuVararu Theodor tvararu Data 24 februarie 2012 17:18:02
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int n;
vector< vector<int> > matAdi;

int main (int argc, char const *argv[])
{
	ifstream in ("royfloyd.in");
	in >> n;
	matAdi.resize(n, vector<int>(n));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
			in >> matAdi[i][j];
	}
	in.close();
	
	/*
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
			cout << matAdi[i][j] << ' ';
		cout << '\n';
	}
	*/
	
	for (int k = 0; k < n; k++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				if (i != j)
					matAdi[i][j] = min (matAdi[i][j], (matAdi[i][k] + matAdi[k][j]));
	
	ofstream out ("royfloyd.out");
	/*
	if (a[i][k] && 
		a[k][j] && 
		(a[i][j] > a[i][k] + a[k][j] || !a[i][j]) && 
		i != j)
		a[i][j] = a[i][k] + a[k][j];*/
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
			out << matAdi[i][j] << ' ';
		out << '\n';
	}
	out.close();
		
	return 0;
}