Pagini recente » Cod sursa (job #1035476) | Cod sursa (job #2419581) | Cod sursa (job #1665137) | Cod sursa (job #1321558) | Cod sursa (job #2576033)
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX_N = 100;
const int INF = 1000000;
int cost[5 + MAX_N][5 + MAX_N];
int main() {
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &cost[i][j]);
if (cost[i][j] == 0)
cost[i][j] = INF + 1;
}
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (k != i && k != j && i != j)
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (cost[i][j] == INF + 1)
cost[i][j] = 0;
printf("%d ", cost[i][j]);
}
printf("\n");
}
return 0;
}