Pagini recente » Atasamentele paginii Clasament dasda | Diferente pentru preoni-2007/runda-4/solutii intre reviziile 25 si 24 | Diferente pentru blog/romanii-la-disneyworld-partea-a-treia intre reviziile 16 si 15 | Cod sursa (job #967528) | Cod sursa (job #2480212)
#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];
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][j] > matrice[i][k] + matrice[k][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();
}