import sys input = sys.stdin.readline def topological_sort(G): ret = [] start = [] par_count = [0] * len(G) for u in range(len(G)): for v, _ in G[u]: par_count[v] += 1 for v in range(len(G)): if par_count[v] == 0: start.append(v) while start: u = start.pop() ret.append(u) for v, _ in G[u]: par_count[v] -= 1 if par_count[v] == 0: start.append(v) if any(c > 0 for c in par_count): # G is not a DAG return None return ret N = int(input()) M = int(input()) G = [[] for _ in range(N)] for _ in range(M): P, Q, R = map(int, input().split()) P -= 1 R -= 1 G[R].append((P, Q)) order = topological_sort(G) ans = [0] * N ans[N-1] = 1 for v in order: if not G[v]: continue for u, c in G[v]: ans[u] += ans[v] * c ans[v] = 0 print(*ans[:-1], sep='\n')