#include<iostream> using namespace std; int main() { int e[10][10], i, j, k, m, n; int t1, t2, t3; int inf = 999999999; cin >> n >> m; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) { if (i == j) e[i][j] = 0; else e[i][j] = inf; } for (i = 1; i <= m; i++) { cin >> t1 >> t2 >> t3; e[t1][t2] = t3; } for (k = 1; k <= n; k++)//弗洛伊德算法 for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) if (e[i][k]<inf&&e[k][j]<inf&&e[i][j] > e[i][k] + e[k][j]) e[i][j] = e[i][k] + e[k][j]; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) cout << e[i][j]<<" "; cout<<endl; } return 0; }