Pagini recente » Cod sursa (job #2009023) | Cod sursa (job #1027367) | Cod sursa (job #3192585) | Cod sursa (job #1377749) | Cod sursa (job #2169889)
#include <bits/stdc++.h>
using namespace std;
ifstream in("date.in");
ofstream out("date.out");
int matrice[110][110];
int main() {
int n; in >> n;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
in >> matrice[i][j];
}
}
for(int k = 1; k <= n; ++k) {
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
if(i != j && matrice[i][k] && matrice[k][j] && (!matrice[i][j])) {
matrice[i][j] = min(matrice[i][j], matrice[i][k] + matrice[k][j]);
}
}
}
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
out << matrice[i][j] << " ";
}
out << '\n';
}
in.close(); out.close();
return 0;
}