Cod sursa(job #3320805)

Utilizator DalvDalvGhita Vladut DalvDalv Data 7 noiembrie 2025 14:41:47
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <algorithm>
#include <ctime>
#include <vector>
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <cmath>
#include <unordered_map>
#include <iomanip>
#include <queue>
#include <tuple>

using namespace std;


int graf[10001][10001];
int dist[10001][10001];

int main() {
	ifstream cin("royfloyd.in");
	ofstream cout("royfloyd.out");

	int n;
	cin >> n;

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			cin >> graf[i][j];

			if(graf[i][j] == 0) dist[i][j] = 1e9;
			else dist[i][j] = graf[i][j];
		}
	}

	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			if(dist[i][j] >= 1e9) cout << 0 << " ";
			
			cout << dist[i][j] << " ";
		}
		cout << endl;
	}
}