from collections import deque N = int(input()) M = int(input()) class Product: def __init__(self, no): self.no = no self.parents = [] self.children = set() self.items = 0 P = [Product(n) for n in range(N)] P[N - 1].items = 1 for _ in range(M): p, q, r = map(int, input().split()) P[r - 1].parents.append((p - 1, q)) P[p - 1].children.add(r - 1) visited = set() # dfs d = deque([P[N - 1]]) while d: product = d.pop() if product.children <= visited: visited.add(product.no) if product.parents: for parent, q in product.parents: P[parent].items += q * product.items d.append(P[parent]) product.items = 0 for n in range(N - 1): print(P[n].items)