Pagini recente » Cod sursa (job #1058030) | Cod sursa (job #819081) | Cod sursa (job #449672) | Cod sursa (job #2382294) | Cod sursa (job #680201)
Cod sursa(job #680201)
#include<cstdio>
const int N = 102;
const int INF = 0x3f3f3f3f;
int n, cost[N][N];
void citire() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
scanf("%d", &cost[i][j]);
}
inline int min(int x, int y) {
return x < y ? x : y;
}
void rez() {
for (int k = 1; k <= n; ++k)
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (i != j && cost[i][k] && cost[k][j] && (!cost[i][j] || cost[i][j] > cost[i][k] + cost[k][j]))
cost[i][j] = cost[i][k] + cost[k][j];
}
void afis() {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j)
printf("%d ", cost[i][j]);
printf("\n");
}
}
int main() {
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
citire();
rez();
afis();
return 0;
}