#include <iostream>
#include <algorithm>
using namespace std;
const int N = 510;
const int INF = 0x3fffffff;
int n, m;
int dis[N][N];
void Floyd() {
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (dis[i][k] != INF && dis[k][j] != INF && dis[i][j] > dis[i][k] + dis[k][j]) {
dis[i][j] = dis[i][k] + dis[k][j];
}
}
}
}
}
int main() {
int u, v, w;
scanf("%d%d", &n, &m);
fill(dis[0], dis[0] + N * N, INF);
for (int i = 0; i < m; i++) {
scanf("%d %d %d", &u, &v, &w);
dis[u][v] = w;
}
Floyd();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%d ", dis[i][j]);
}
printf("\n");
}
return 0;
}
/******************
6 8
0 1 1
0 3 4
0 4 4
1 3 2
2 5 1
3 2 2
3 4 3
4 5 3
输出:
1073741823 1 5 3 4 6
1073741823 1073741823 4 2 5 5
1073741823 1073741823 1073741823 1073741823 1073741823 1
1073741823 1073741823 2 1073741823 3 3
1073741823 1073741823 1073741823 1073741823 1073741823 3
1073741823 1073741823 1073741823 1073741823 1073741823 1073741823
*******************/