#include using namespace std; vector topolo(vector>> &Graph){ int siz = Graph.size(); vector ret,inV(siz); for(auto u : Graph) for(auto [to,w] : u) inV.at(to)++; queue Q; for(int i=siz-1; i> N >> M; vector>> Graph(N),rev(N); for(int i=0; i> a >> b >> c; a--; c--; assert(a != N-1); Graph.at(c).push_back({a,b}); } auto topo = topolo(Graph); vector need(N); need.at(N-1) = 1; for(auto pos : topo) for(auto [to,w] : Graph.at(pos)) need.at(to) += need.at(pos)*w; for(int i=0; i