# BZOJ2049 SDOI2008 Cave 洞穴勘测

200 5
Query 123 127
Connect 123 127
Query 123 127
Destroy 127 123
Query 123 127

3 5
Connect 1 2
Connect 3 1
Query 2 3
Destroy 1 3
Query 2 3

No
Yes
No

Yes
No

### HINT

#include<bits/stdc++.h>
using namespace std;
const int N=1e4+10,INF=1e9;
int ans=0,w=1;char c=getchar();
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')w=-1,c=getchar();
while(isdigit(c))ans=ans*10+c-'0',c=getchar();
return ans*w;
}
int n,m;
int fa[N],son[N][2],st[N];
bool rev[N]={0};
inline bool isroot(int x){
return son[fa[x]][0]!=x&&son[fa[x]][1]!=x;
}
void pushdown(int x){
if(rev[x]){
rev[x]^=1;
rev[son[x][0]]^=1;
rev[son[x][1]]^=1;
swap(son[x][0],son[x][1]);
}
}
inline bool Son(int t){
return son[fa[t]][1]==t;
}
inline void rotate(int x){
int f=fa[x],g=fa[f],a=Son(x),b=a^1;
if(!isroot(f)){
if(Son(f))son[g][1]=x;
else son[g][0]=x;
}
fa[x]=g;
fa[f]=x;son[f][a]=son[x][b];
fa[son[x][b]]=f;son[x][b]=f;
}
void splay(int x){
int top=0;st[++top]=x;
for(int i=x;!isroot(i);i=fa[i])st[++top]=fa[i];
for(int i=top;i;i--)pushdown(st[i]);
while(!isroot(x)){
int f=fa[x];
if(!isroot(f)){
if(Son(x)^Son(f))rotate(x);
else rotate(f);
}
rotate(x);
}
}
void access(int x){
int t=0;
while(x){
splay(x);
son[x][1]=t;
t=x;x=fa[x];
}
}
void reverse(int x){
access(x);
splay(x);
rev[x]^=1;
}
void link(int x,int y){
reverse(x);
fa[x]=y;
splay(x);
}
void cut(int x,int y){
reverse(x);
access(y);
splay(y);
son[y][0]=fa[x]=0;
}
int find(int x){
access(x);
splay(x);
while(son[x][0])x=son[x][0];
return x;
}
int main(){
char ch[10];
for(int i=1;i<=m;i++){
scanf("%s",ch);
}