Cod sursa(job #3256233)

Utilizator Tudor.1234Holota Tudor Matei Tudor.1234 Data 13 noiembrie 2024 21:13:05
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include "bits/stdc++.h"
const int SIZE = 100;
int dist[SIZE + 5][SIZE + 5];
int n;
void Debug(){
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			std :: cout << dist[i][j] << ' ';
		}
		std :: cout << '\n';
	}
}
void Floyd(){
	for(int k = 1; k <= n; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(dist[i][j] > dist[i][k] + dist[k][j]){
					dist[i][j] = dist[i][k] + dist[k][j];
				}
			}
		}
	}
}
void Solve(){
	std :: cin >> n;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			std :: cin >> dist[i][j];
		}
	}
	Floyd();
	Debug();
}
signed main(){
	freopen("royfloyd.in", "r", stdin);
	freopen("royfloyd.out", "w", stdout);
	std :: ios_base :: sync_with_stdio(false);
	std :: cin.tie(0);
	std :: cout.tie(0);
	Solve();
	return 0;
}