1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
#include<bits/stdc++.h> #define re register typedef long long ll; template<class T> inline void read(T &x) { x=0; char ch=getchar(),t=0; while(ch<'0'||ch>'9') t|=ch=='-',ch=getchar(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); if(t) x=-x; } template<class T,class ...T1> inline void read(T &x,T1 &...x1){ read(x),read(x1...); } template<class T> inline void write(T x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } template<> inline void write(bool x){ putchar(x?'1':'0'); } template<> inline void write(char c){ putchar(c); } template<> inline void write(char *s){ while(*s!='\0') putchar(*s++); } template<> inline void write(const char *s){ while(*s!='\0') putchar(*s++); } template<class T,class ...T1> inline void write(T x,T1 ...x1){ write(x),write(x1...); } template<class T> inline bool checkMax(T &x,T y){ return x<y?x=y,1:0; } template<class T> inline bool checkMin(T &x,T y){ return x>y?x=y,1:0; } const int MAXN=2e5+10,MAXM=5e5+10,MAXS=20; int N,M,Q; struct G { int next,to; }Edge[MAXN<<1],NewEdge[MAXN<<1]; int Head[MAXN],Total,NewHead[MAXN],NewTotal; inline void addEdge(int u,int v) { Edge[++Total]=(G){Head[u],v};Head[u]=Total; Edge[++Total]=(G){Head[v],u};Head[v]=Total; } inline void addNewEdge(int u,int v) { NewEdge[++NewTotal]=(G){NewHead[u],v};NewHead[u]=NewTotal; NewEdge[++NewTotal]=(G){NewHead[v],u};NewHead[v]=NewTotal; } int Dfn[MAXN],Low[MAXN],Cnt,Bcc_cnt; bool Ins[MAXN]; std::stack<int>Stk; std::set<int>Set1,Set2[MAXN]; void Tarjan(int x,int last,int n,int &id,int &bcc_cnt) { int son_cnt=0; Dfn[x]=Low[x]=++id,Ins[x]=1,Stk.push(x); for(int e=Head[x],v;e;e=Edge[e].next) { if(!Ins[(v=Edge[e].to)]) { ++son_cnt; Tarjan(v,x,n,id,bcc_cnt); checkMin(Low[x],Low[v]); if(Low[v]>=Dfn[x]) { int pos=++bcc_cnt+N,cur; addNewEdge(pos,x); do { cur=Stk.top();Stk.pop(); addNewEdge(pos,cur); }while(cur!=v); } } else checkMin(Low[x],Dfn[v]); } if(!last&&!son_cnt) { int pos=++bcc_cnt+N; addNewEdge(pos,x); } } int Dep[MAXN],In[MAXN],Out[MAXN],Idx; int Dp1[MAXN],Dp2[MAXN],Fa[MAXN][MAXS]; void dfsGraph(int x,int last,int n,int &id) { Dep[x]=Dep[last]+1; int t=std::log2(Dep[x]); In[x]=++id,Fa[x][0]=last; for(int i=1;i<=t;++i) Fa[x][i]=Fa[Fa[x][i-1]][i-1]; Dp1[x]=1; for(int e=NewHead[x],v;e;e=NewEdge[e].next) { v=NewEdge[e].to; if(v==last) continue; dfsGraph(v,x,n,id); Dp1[x]&=Dp1[v]; if(x>n) Dp1[x]&=Set2[last].count(v); } Out[x]=id; } void dfsCalc(int x,int n) { int cnt1=0; Set1.clear(); if(Fa[x][0]!=0) Set1.insert(Fa[x][0]); for(int e=NewHead[x],v;e;e=NewEdge[e].next) { v=NewEdge[e].to; if(v==Fa[x][0]) continue; Set1.insert(v); if(!Dp1[v]) ++cnt1; } int siz=Set1.size(); for(int e=NewHead[x],v;e;e=NewEdge[e].next) { v=NewEdge[e].to; if(v==Fa[x][0]) continue; Dp2[v]=Dp2[x]&&(cnt1==0||(cnt1==1&&!Dp1[v])); if(x>N) { int cnt2=0; for(int e1=Head[v];e1;e1=Edge[e1].next) if(Set1.count(Edge[e1].to)) ++cnt2; Dp2[v]&=cnt2+1==siz; } } for(int e=NewHead[x],v;e;e=NewEdge[e].next) { v=NewEdge[e].to; if(v==Fa[x][0]) continue; dfsCalc(v,n); } } inline bool check(int u,int v){ return In[u]<=In[v]&&In[v]<=Out[u]; } inline int jump(int x,int k) { for(int i=0;(1<<i)<=k;++i) if(k>>i&1) x=Fa[x][i]; return x; } int main() { read(N,M,Q); for(int i=1,u,v;i<=M;++i) { read(u,v); Set2[u].insert(v),Set2[v].insert(u); addEdge(u,v); } Tarjan(1,0,N,Cnt,Bcc_cnt); dfsGraph(1,0,N,Idx); Dp2[1]=1; dfsCalc(1,N); for(int i=1;i<=N;++i) if(Dp1[i]&&Dp2[i]) { for(int qx,qy;Q--;) { read(qx,qy); puts("Yes"); } return 0; } for(int x,y;Q--;) { read(x,y); if(!check(x,y)) { if(Dp2[x]) puts("Yes"); else puts("No"); } else if(Dp1[jump(y,Dep[y]-Dep[x]-1)]) puts("Yes"); else puts("No"); } return 0; }
|