Cod sursa(job #3325474)

Utilizator Dana1000Dana Vidroiu Dana1000 Data 25 noiembrie 2025 15:29:06
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include<iostream> 
#include<fstream>
#include<vector>

using namespace std;
ifstream fcin("royfloyd.in");
ofstream fcout("royfloyd.out");

const int INF = 1e9;


int main()
{
	int n;
	fcin >> n; 

	vector<vector<int>> dist(n, vector<int>(n));

	for (int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
		{
			fcin >> dist[i][j];
			if (i != j && dist[i][j] == 0)
				dist[i][j] = INF;
		}

	for (int k = 0; k < n; k++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				if (dist[i][k] < INF && dist[k][j] < INF)
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
			if (dist[i][j] == INF)
				fcout << 0 << " ";
			else
				fcout << dist[i][j] << " ";

		fcout << endl;
	}

}