rt
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits>
#include<vector>
using namespace std;
int n, m;
const int INF = numeric_limits<int>::max();
int e[102][102];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j) e[i][j] = 0;
else e[i][j] = INF;
}
}
for (int i = 0; i < m; i++) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
e[u][v] = w;
e[v][u] = w;
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
e[i][j] = min(e[i][j], e[i][k] + e[k][j]);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
printf("%d ", e[i][j]);
printf("\n");
}
return 0;
}