Cod sursa(job #3325421)

Utilizator r0scatRosca Teodora Maia r0scat Data 25 noiembrie 2025 13:34:05
Problema Floyd-Warshall/Roy-Floyd Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <utility>
#include <fstream>
#include <climits>

using namespace std;

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

const int INF = INT_MAX;


int distanta[101][101];

int main() {
	int n;
	fin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			fin >> distanta[i][j];
			if (distanta[i][j] == 0 && i != j) {
				distanta[i][j] = INF;
			}
		}
	}

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

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (distanta[i][j] == INF) {
				fout << 0 << " ";
			}
			else {
				fout << distanta[i][j] << " ";
			}
		}
		fout << "\n";
	}


	return 0;
}