#include #pragma GCC optimize("Ofast") using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll I=1167167167167167167; ll Q=998244353; #define rep(i,a) for (ll i=0;i using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,const T &b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} template void print_tate(vector &v) {rep(i,v.size()) cout<> G(200200); vector> H(200200); int ran[200200]; int r=0; void dfs(int a,int &now){ if(order[a]!=-1) return ; order[a]=-2; for(auto x:G[a]){ dfs(x,now); } order[a]=now; now++; } void dfs_2(int a){ if(ran[a]!=-1) return ; ran[a]=r; for(auto x:H[a]) dfs_2(x); } namespace po167{ struct UFtree { std::vector par; std::vector wei; UFtree(int n):par(n),wei(n){ for(int i=0;i>N>>M; rep(i,M){ int a,b; cin>>a>>b; a--,b--; G[a].push_back(b); H[b].push_back(a); } vector> ans; rep(i,N) order[i]=-1,ran[i]=-1; int now=0; rep(i,N){ dfs(i,now); } int p[N]; rep(i,N) p[order[i]]=i; //cout<>>> q(r); vector> F(r); UFtree A(r); rep(i,N){ int a=ran[i]; F[a].push_back(i); for(auto x:G[i]){ int b=ran[x]; q[a].push_back({b,{i,x}}); } } for(int i=0;i