Cod sursa(job #3203240)

Utilizator AlexMoto2006Motoasca Alexandru-Lucian AlexMoto2006 Data 13 februarie 2024 12:55:36
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>

using namespace std;

ifstream cin("royfloyd.in");
ofstream cout("royfloyd.in");
int n,a[101][101];
int max1 = 100000;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cin >> a[i][j];
			if (a[i][j] == 0 && i != j)
			{
				a[i][j] = max1;
			}
		}
	}
	for (int k = 1; k <= n; k++)
	{
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)
			{
				if (a[i][j] > a[i][k] + a[k][j])
				{
					a[i][j] = a[i][k] + a[k][j];
				}
			}
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for(int j=1;j<=n;j++)
			if (a[i][j] == max1)
			{
				cout <<0<<" ";
			}
			else
			{
				cout << a[i][j] << " ";
			}
		cout << "\n";
	}
    return 0;
}