Pagini recente » Cod sursa (job #2500427) | Cod sursa (job #3041595) | Cod sursa (job #1261828) | Cod sursa (job #1716743) | Cod sursa (job #3325404)
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
fin >> n;
int chestie[120][120];
for (int a = 1; a <= n; a++) {
for (int b = 1; b <= n; b++) {
fin >> chestie[a][b];
if (a != b && chestie[a][b] == 0) chestie[a][b] = 999999999;
}
}
for (int x = 1; x <= n; x++) {
for (int y = 1; y <= n; y++) {
for (int z = 1; z <= n; z++) {
int t1 = chestie[y][x];
int t2 = chestie[x][z];
if (t1 != 999999999 && t2 != 999999999) {
int t3 = t1 + t2;
if (t3 < chestie[y][z]) chestie[y][z] = t3;
}
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
fout << (chestie[i][j] == 999999999 ? 0 : chestie[i][j]) << " ";
}
fout << "\n";
}
return 0;
}