#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- template class UF { public: vector par,rank,cnt; UF() {par=rank=vector(um,0); cnt=vector(um,1); for(int i=0;irank[y]) return par[x]=y; rank[x]+=rank[x]==rank[y]; return par[y]=x; } }; class SCC_ART { public: static const int MV = 110000; int NV,time; vector > E; vector low,num,isart,gr; vector> ES; vector > SC; // out vector ART; // out vector> > BE; // out, Edgeset UF uf; void init(int NV=MV) { this->NV=NV; E.clear(); E.resize(NV);} void add_edge(int x,int y) { E[x].push_back(y); E[y].push_back(x);} void dfs(int cur,int pre) { low[cur]=num[cur]=++time; FORR(e,E[cur]) { if(e!=pre && num[e]2) || (num[cur]!=1&&low[e]>=num[cur])) isart[cur]=1; if(low[e]>=num[cur]) { BE.push_back(set>()); while(1) { pair te=ES.back(); ES.pop_back(); BE.back().insert(te); if(min(cur,e)==te.first && max(cur,e)==te.second) break; } } } } if(isart[cur]) ART.push_back(cur); } void scc() { ART.clear();uf.reinit();SC.clear();BE.clear();ES.clear(); low=num=isart=gr=vector(NV,0); for(int i=0;i()); for(int i=0;i,int> ME; int A[101010],B[101010]; vector E[303030]; set NE[303030]; UF<303030> uf; int isart[301010],isarts[301010]; vector V[303030]; int P[21][300005],D[300005]; void dfs(int cur,int ps) { ps+=isart[cur]; isarts[cur]=ps; FORR(e,E[cur]) if(e!=P[0][cur]) D[e]=D[cur]+1, P[0][e]=cur, dfs(e,ps); } int getpar(int cur,int up) { int i; FOR(i,20) if(up&(1<D[bb]) swap(aa,bb); for(i=19;i>=0;i--) if(D[bb]-D[aa]>=1<=0;i--) if(P[i][aa]!=P[i][bb]) aa=P[i][aa], bb=P[i][bb]; return (aa==bb)?aa:P[0][aa]; // vertex } void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>M; scc.init(N); FOR(i,M) { cin>>A[i]>>B[i]; A[i]--; B[i]--; scc.add_edge(A[i],B[i]); } scc.scc(); FORR(a,scc.ART) { isart[a]=1; } FOR(i,scc.BE.size()) { set S; FORR2(a,b,scc.BE[i]) S.insert(a),S.insert(b); FORR(s,S) E[N+i].push_back(s), E[s].push_back(N+i); } dfs(0,0); FOR(i,19) FOR(x,N+M*2) P[i+1][x]=P[i][P[i][x]]; cin>>Q; while(Q--) { cin>>x>>y; x--; y--; if(x==y) { cout<<0<