Pagini recente » Cod sursa (job #1509113) | Cod sursa (job #2791442) | Cod sursa (job #1300383) | Cod sursa (job #1132823) | Cod sursa (job #1908888)
#include <bits/stdc++.h>
using namespace std;
const int nMax = 102;
const int INF = 1e8;
int n, cost[nMax][nMax], dp[nMax][nMax];
int main() {
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
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])
cost[i][j] = INF;
dp[i][j] = cost[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 and i != k and j != k) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (dp[i][j] == INF)
printf("%d ", 0);
else printf("%d ", dp[i][j]);
}
printf("\n");
}
return 0;
}