Pagini recente » Cod sursa (job #1335672) | Cod sursa (job #1102647) | Cod sursa (job #1725417) | Cod sursa (job #2030734) | Cod sursa (job #2673225)
/*
`-/oo+/- ``
.oyhhhhhhyo.`od
+hhhhyyoooos. h/
+hhyso++oosy- /s
.yoooossyyo:``-y`
..----.` ``.-/+:.`
`````..-::/.
`..```.-::///`
`-.....--::::/:
`.......--::////:
`...`....---:::://:
`......``..--:::::///:`
`---.......--:::::////+/`
----------::::::/::///++:
----:---:::::///////////:`
.----::::::////////////:-`
`----::::::::::/::::::::-
`.-----:::::::::::::::-
...----:::::::::/:-`
`.---::/+osss+:`
``.:://///-.
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugsp(x) cerr << #x << " " << x << " "
using namespace std;
const int INF = 2e9;
const int N = 100;
int dp[5 + N][5 + N];
int n;
void Roy_Floyd() {
for(int k = 1; k <= n; k++) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(i != j) {
if(dp[i][k] != 0 && dp[k][j] != 0 && (dp[i][k] + dp[k][j] < dp[i][j] || dp[i][j] == 0))
dp[i][j] = dp[i][k] + dp[k][j];
}
}
}
}
}
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", &dp[i][j]);
}
Roy_Floyd();
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++)
printf("%d ", dp[i][j]);
printf("\n");
}
fclose(stdin);
fclose(stdout);
return 0;
}