Pagini recente » Cod sursa (job #1167379) | Cod sursa (job #499435) | Cod sursa (job #2963660) | Cod sursa (job #1256547) | Cod sursa (job #2533461)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int const maxim = 1005;
int matrice[maxim][maxim] = { 0 };
int n;
void citire() {
in >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
in >> matrice[i][j];
}
}
}
void roy() {
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (matrice[i][k] && matrice[k][j] && (matrice[i][k] + matrice[k][j] < matrice[i][j] || !matrice[i][j]) && i != j)
matrice[i][j] = matrice[i][k] + matrice[k][j];
}
}
}
}
void afisare() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
out << matrice[i][j] << " ";
}
out << endl;
}
}
int main() {
citire();
roy();
afisare();
return 0;
}