n, m = map(int, input().split()) INF = 10**18 d = [[INF]*n for _ in range(n)] for i in range(n): d[i][i] = 0 for i in range(m): s, t, w = map(int, input().split()) s, t = s-1, t-1 d[s][t] = min(d[s][t], w) def warshal_floyd(d): n = len(d) for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j], d[i][k]+d[k][j]) return d d = warshal_floyd(d) ans = [0]*n for i in range(n): for j in range(n): if d[i][j] == INF: continue ans[i] += d[i][j] print(*ans, sep='\n')