Cod sursa(job #3348082)

Utilizator nverde1119Popa Narcis Constantin nverde1119 Data 19 martie 2026 16:48:59
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <iostream>
#include <fstream>

using namespace std;
int n, A[101][101];
const int inf = 9999999;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
void citire()
{
	f >> n;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
			f >> A[i][j];
	}
}
void rf()
{
	int cost;
	for(int k = 1; k <= n; k++)
	{
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= n; j++)
			{
				cost = A[i][k] + A[k][j];
				if(A[i][j] > cost && i!=j)
					A[i][j] = cost;
			}
		}
	}
}
void afis()
{
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
			g << A[i][j] << ' ';
		g << '\n';
	}
}
int main()
{
	citire();
	rf();
	afis();
	return 0;
}