#include using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() // 昇順ソート #define rall(v) (v).rbegin(), (v).rend() // 降順ソート #define INF 1LL << 60 typedef long long int LL; typedef long long int ll; #define pll pair #define F first #define S second const int MOD = 1000000007; template bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; } //sort(all(x))とするとソートできるよ // 10^x は pow(10,(x)) // 任意のlogは 対数の底の変換を使う log(N) / log(任意の底) int N,M; vector> G; vector buy; void dfs(int n,LL sum){ if(G[n].size() == 0)buy[n] += sum; else{ for(auto t : G[n]){ int to = t.F; LL vl = t.S; dfs(to,sum * vl); } } } int main(){ cin >> N >> M; G.resize(N); buy.resize(N); rep(i,M){ LL P,Q,R;cin >> P >> Q >> R; P--;R--; G[R].push_back({P,Q}); } dfs(N-1,1); rep(i,N-1)cout << buy[i] << endl; }