void main() { const N = readInt; const M = readInt; auto P = new int[M]; auto Q = new int[M]; auto R = new int[M]; auto G = new int[][](N, 0); foreach (i; 0 .. M) { P[i] = readInt; Q[i] = readInt; R[i] = readInt; P[i]--; R[i]--; G[R[i]] ~= i; } auto ans = new long[N - 1]; void dfs(int u, long now) { if (G[u].empty) { ans[u] += now; } else { foreach (i; G[u]) { int v = u ^ P[i] ^ R[i]; dfs(v, now * Q[i]); } } } dfs(N - 1, 1); foreach (i; 0 .. N - 1) { writeln(ans[i]); } } import std,core.bitop; string[]_R; string readString(){while(_R.empty){_R=readln.chomp.split;}auto ret=_R.front;_R.popFront;return ret;} int readInt(){return readString.to!int;} long readLong(){return readString.to!long;} real readReal(){return readString.to!real;} bool chmin(T)(ref T A,T B){if(A>B){A=B;return true;}else{return false;}} bool chmax(T)(ref T A,T B){if(A1){int mid=(L+R)/2;(A[mid]1){int mid=(L+R)/2;(A[mid]<=x?L:R)=mid;}return R;}