Cod sursa(job #1336637)

Utilizator BionicMushroomFMI - Dumitrescu Tiberiu Alexandru BionicMushroom Data 7 februarie 2015 23:50:25
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include<fstream>
#include<algorithm>
using namespace std;

int main()
{
	ifstream in_file("royfloyd.in");
	int **shortest_paths, vertex_number;
	in_file >> vertex_number;
	shortest_paths = new int*[vertex_number];
	for (short i = 0; i < vertex_number; ++i)
	{
		shortest_paths[i] = new int[vertex_number];
		for (short j = 0; j < vertex_number; ++j)
			in_file >> shortest_paths[i][j];
	}
	in_file.close();
	for (short k = 0; k < vertex_number; ++k)
		for (short i = 0; i < vertex_number; ++i)
			for (short j = 0; j < vertex_number; ++j)
				shortest_paths[i][j] = min(shortest_paths[i][j], shortest_paths[i][k] + shortest_paths[k][j]);
	ofstream out_file("royfloyd.out");
	for (int i = 0; i < vertex_number; ++i)
	{
		for (int j = 0; j < vertex_number; ++j)
			out_file << shortest_paths[i][j] << ' ';
		out_file << '\n';
	}
	for (short i = 0; i < vertex_number; ++i)
		delete[] shortest_paths[i];
	delete[] shortest_paths;
	return 0;
}