Cod sursa(job #2305872)

Utilizator dey44andIoja Andrei-Iosif dey44and Data 21 decembrie 2018 11:54:38
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <fstream>

#define NMAX 105

using namespace std;

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

int cost[NMAX][NMAX], N;

int Min(int a, int b)
{
	return a < b ? a : b;
}

void Read()
{
	in >> N;
	for (int i = 1; i <= N; i++)
	for (int j = 1; j <= N; j++)
		in >> cost[i][j];
}

void Solve()
{
	for (int k = 1; k <= N; k++)
	for (int i = 1; i <= N; i++)
	for (int j = 1; j <= N; j++)
	if (i != j)
	{
		if (cost[i][k] && cost[k][j] && cost[i][j] > cost[i][k] + cost[k][j])
			cost[i][j] = cost[i][k] + cost[k][j];
	}
}

void Print_Sol()
{
	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= N; j++)
			out << cost[i][j] << " ";
		out << "\n";
	}
}


int main()
{
	Read();
	Solve();
	Print_Sol();
	return 0;
}