Cod sursa(job #3285425)

Utilizator andrei_C1Andrei Chertes andrei_C1 Data 12 martie 2025 20:50:24
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>
using namespace std;

void ckmin(int &x, int y) {
	if(y < x) {
		x = y;
	}
}

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
#ifdef INFOARENA
	freopen("royfloyd.in", "r", stdin);
	freopen("royfloyd.out", "w", stdout);
#endif
	int n;
	cin >> n;
	vector<vector<int>> dist(n, vector<int>(n));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cin >> dist[i][j];
		}
	}
	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] && dist[k][j]) {
					ckmin(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cout << dist[i][j] << " ";
		}
		cout << '\n';
	}
	return 0;
}