#include #include #include using namespace std; class TopologicalSort{ private: int n; vector> g; vector p; public: TopologicalSort():TopologicalSort(0){} TopologicalSort(int _n): n(_n), g(_n){} void add_edge(int u, int v){ g[u].push_back(v); } bool build(){ vector cnt(n); for(int v=0; v que; for(int v=0; v> N >> M; vector>> g(N); TopologicalSort tp(N), tp_inv(N); for(int i=0; i> u >> v >> w; g[u].push_back(make_pair(v,w)); tp.add_edge(u, v); tp_inv.add_edge(v, u); } tp.build(); tp_inv.build(); vector dp(N,0), ep(N,1<<30); dp[0] = ep[0] = 0; for(int i=0; i