#include #include #include using namespace std; long S[100]; vector >G[100]; int N,M; int cnt[100]; main() { cin>>N>>M; for(int i=0;i>p>>q>>r; G[r-1].push_back(make_pair(p-1,q)); cnt[p-1]++; } S[N-1]=1; queueP; P.push(N-1); while(!P.empty()) { int i=P.front();P.pop(); if(!G[i].empty()) { for(pairp:G[i]) { S[p.first]+=S[i]*p.second; cnt[p.first]--; if(cnt[p.first]==0)P.push(p.first); } S[i]=0; } } for(int i=0;i