Pagini recente » Cod sursa (job #145999) | Cod sursa (job #401479) | Cod sursa (job #3276055) | Cod sursa (job #2759287) | Cod sursa (job #631201)
Cod sursa(job #631201)
#include <cstdio>
#include <algorithm>
using namespace std;
int cost[101][101];
int main (void) {
int n;
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
scanf("%d", &n);
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j) {
scanf("%d", &cost[i][j]);
if(cost[i][j] == 0 && i != j)
cost[i][j] = 999999;
}
for(int k = 0; k < n; ++k)
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j)
printf("%d ", cost[i][j] * (cost[i][j] != 0));
printf("\n");
}
}