#include <iostream> #include <iomanip> using namespace std; int m, n; int e[10010][10010], u, v, w; int main(){ cin >> 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] = 999999999; for(int i = 1; i <= m; i ++){ cin >> u >> v >> w; e[u][v] = w; } for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) if(e[i][j] > e[i][k] + e[k][j]) e[i][j] = e[i][k] + e[k][j]; for(int i = 1; i <= n; i ++){ for(int j = 1; j <= n; j ++) cout << setw(5) << e[i][j]; cout << endl; } return 0; }