Pagini recente » Cod sursa (job #1600513) | Cod sursa (job #2564718) | Cod sursa (job #2907808) | Cod sursa (job #1878719) | Cod sursa (job #2480216)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int const maxim = 105;
int const oo = (1 << 30);
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 solve() {
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][j] > matrice[i][k] + matrice[k][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();
solve();
afisare();
}