https://www.acmicpc.net/problem/11403
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int int64_t
using namespace std;
int dist[101][101];
const int INF = 1e9 + 7;
int32_t main() {
fastio;
int n; cin >> n;
for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++){
int t; cin >> t;
if(t) dist[i][j] = t;
else dist[i][j] = INF;
}
// floyd
for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++){
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cout << (dist[i][j]==INF ? 0 : 1) << ' ';
}
cout << "\n";
}
}