Cod sursa(job #3320808)

Utilizator DalvDalvGhita Vladut DalvDalv Data 7 noiembrie 2025 14:44:32
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 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 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 >> dist[i][j];
			if(dist[i][j] == 0 && i != j) dist[i][j] = 1e9;
		}
	}

	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 << dist[i][j] << " ";
			else cout << 0 << " ";
		}
		cout << endl;
	}
}