Pagini recente » Cod sursa (job #668380) | Cod sursa (job #172136) | Cod sursa (job #220053) | Cod sursa (job #1076698) | Cod sursa (job #2684050)
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long LL;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<LL, LL>
#define sz(x) (int)((x).size())
#define int long long
#define cin in
#define cout out
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int inf = 2e9;
const LL mod = 1e9 + 7;
const int N = 2e3 + 11;
const LL INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
int n, m, dp[N][N];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++){
for(int j = 1, x; j <= n; j++){
cin >> x;
dp[i][j] = (x == 0 ? inf : x);
if(i == j)dp[i][j] = 0;
}
}
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1, x; j <= n; j++){
cout << (dp[i][j] == inf ? 0: dp[i][j]) << ' ';
}cout << '\n';
}
}
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << setprecision(6) << fixed;
int T = 1;
//cin >> T;
while(T--){
solve();
}
}