Cod sursa(job #2772721)

Utilizator rARES_4Popa Rares rARES_4 Data 2 septembrie 2021 15:31:13
Problema Floyd-Warshall/Roy-Floyd Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int n;
int costuri[101][101];
int main()
{
	f >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			f >> costuri[i][j];
			if (!costuri[i][j] && i != j)
			{
				costuri[i][j] = INT_MAX;
			}
		}
	}
	for (int k = 1; k <= n; k++)
	{
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)
			{
				if (costuri[i][j] > costuri[i][k] + costuri[k][j])
				{
					costuri[i][j] = costuri[i][k] + costuri[k][j];
				}
			}
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (costuri[i][j] == INT_MAX)
				g << "0 ";
			else
				g << costuri[i][j] << " ";
		}
		g << endl;

	}

}