Cod sursa(job #3300823)

Utilizator MihaiZ777MihaiZ MihaiZ777 Data 19 iunie 2025 12:25:32
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.05 kb
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <fstream>
#include <cstring>
#include <vector>
using namespace std;

#define fast_io ios::sync_with_stdio(0); cin.tie(0); do{}while(0)
typedef long long ll;

const int MAXN = 105;
const int INF = 0x3f3f3f3f;

ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");

int n;
int graph[MAXN][MAXN];

void ReadData() {
	fin >> n;
	int a;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			fin >> a;
			graph[i][j] = a;
		}
	}
}

void RoyFloyd() {
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (graph[i][j] <= graph[i][k] + graph[k][j]) {
					continue;
				}
				graph[i][j] = graph[i][k] + graph[k][j];
			}
		}
	}
}

void Solve() {
	RoyFloyd();
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			fout << graph[i][j] << ' ';
		}
		fout << '\n';
	}
}

int main() {
		ReadData();
		Solve();
		return 0;
}