from collections import defaultdict import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix N, M = map(int, input().split()) length, frm, to = [], [], [] MAX = 10 ** 13 edges_dict = defaultdict(lambda: MAX) for _ in range(M): s, t, d = map(int, input().split()) s -= 1 t -= 1 edges_dict[(s, t)] = min(edges_dict[(s, t)], d) for (s, t), d in edges_dict.items(): length.append(d) frm.append(s) to.append(t) matr = csr_matrix((length, (frm, to)), shape=(N, N)) way = floyd_warshall(matr) way = np.where(np.isinf(way), 0, way.astype(np.int64)) print(*way.sum(axis=1), sep='\n')