# [BZOJ2049] [SDOI2008] 洞穴勘测

## 输入输出样例

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

No
Yes
No


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

Yes
No

## 说明

10%的数据满足n≤1000, m≤20000

20%的数据满足n≤2000, m≤40000

30%的数据满足n≤3000, m≤60000

40%的数据满足n≤4000, m≤80000

50%的数据满足n≤5000, m≤100000

60%的数据满足n≤6000, m≤120000

70%的数据满足n≤7000, m≤140000

80%的数据满足n≤8000, m≤160000

90%的数据满足n≤9000, m≤180000

100%的数据满足n≤10000, m≤200000

 1 //minamoto
2 #include<cstdio>
3 #include<algorithm>
4 #include<cctype>
5 #include<map>
6 #define N 10005
7 using namespace std;
9     #define num ch-'0'
10     char ch;bool flag=0;int res;
11     while(!isdigit(ch=getchar()))
12     (ch=='-')&&(flag=true);
13     for(res=num;isdigit(ch=getchar());res=res*10+num);
14     (flag)&&(res=-res);
15     #undef num
16     return res;
17 }
18 namespace lct{
19     int top,s[N],ch[N][2],fa[N];bool rev[N];
20     bool isroot(int x){return ch[fa[x]][0]!=x&&ch[fa[x]][1]!=x;}
21     void pushdown(int x){if(rev[x])swap(ch[x][0],ch[x][1]),rev[ch[x][0]]^=1,rev[ch[x][1]]^=1,rev[x]^=1;}
22     void rotate(int x){
23         int y=fa[x],z=fa[y],d=(ch[y][1]==x);if(!isroot(y)) ch[z][ch[z][1]==y]=x;
24         fa[x]=z,fa[y]=x;fa[ch[x][d^1]]=y,ch[y][d]=ch[x][d^1],ch[x][d^1]=y;
25     }
26     void splay(int x){
27         s[top=1]=x;for(int i=x;!isroot(i);i=fa[i]) s[++top]=fa[i];for(int i=top;i>=1;--i) pushdown(s[i]);
28         for(int y=fa[x],z=fa[y];!isroot(x);y=fa[x],z=fa[y]){
29             if(!isroot(y)) ((ch[z][1]==y)^(ch[y][1]==x))?rotate(x):rotate(y);rotate(x);
30         }
31     }
32     void access(int x){int t=0;while(x){splay(x),ch[x][1]=t,t=x,x=fa[x];}}
33     void makeroot(int x){access(x),splay(x),rev[x]^=1;}
34     int findroot(int x){access(x);splay(x);pushdown(x);while(ch[x][0]) pushdown(x=ch[x][0]);return x;}
36     void cut(int x,int y){makeroot(x),access(y),splay(y),fa[x]=ch[y][0]=0;}
37 }
38 using namespace lct;
39 int main(){
40     //freopen("testdata.in","r",stdin);
41     int n,m;
43     while(m--){
44         char s[10];int u,v;
53 }