def floyd_warshall(n, Edges): """ n: number of vertices Edges: set of edges """ sp = [[float('inf')]*n for _ in range(n)] for init, end, weight in Edges: sp[init][end] = weight #no multi edge for i in range(n): sp[i][i] = 0 for i in range(n): for j in range(n): for k in range(n): if sp[i][j] > sp[i][k]+sp[k][j]: sp[i][j] = sp[i][k]+sp[k][j] return sp N, M = map(int, input().split()) #N頂点、M辺 #辺集合 Edges = set() for _ in range(M): s, t, d = map(int, input().split()) Edges.add((s-1, t-1, d)) #到達不可能な場合0にする設定 sp = floyd_warshall(N, Edges) for i in range(N): print(sum(l if l < float('inf') else 0 for l in sp[i]))