from collections import * N = int(input()) M = int(input()) G = [[] for i in range(N)] for i in range(M): p, q, r = map(int, input().split()) p, r = p - 1, r - 1 G[r].append((p, q)) Q = deque([N - 1]) ans = [0] * N ans[-1] = 1 while Q: u = Q.popleft() for v, c in G[u]: ans[v] += ans[u] * c Q.append(v) if len(G[u]): ans[u] = 0 for i in range(N - 1): print(ans[i])