#include #include #include using namespace std; using ll = long long; using P = pair; int main(void){ int n, m; cin >> n >> m; vector> to(n); while(m--){ int p, q, r; cin >> p >> q >> r; p--, r--; to[r].emplace_back(p, q); } vector ans(n); ans[n-1]=1; auto dfs=[&](auto dfs, int now, int par=-1)->void { bool leaf=true; for(auto [v, per]:to[now])if(v!=par){ ans[v]+=ans[now]*per; dfs(dfs, v, now); leaf=false; } if(!leaf) ans[now]=0; }; dfs(dfs, n-1); for(int i=0; i