【bzoj 2049】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

 1 #include<cstdio>
2 #include<cstring>
3 #include<algorithm>
4 const int N=10050;
5 using namespace std;
6 int n,m,a,b,c[N][2],fa[N],st[N];
7 bool rev[N];
9 {
10     int x=0,f=1;char c=getchar();
11     while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
12     while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
13     return x*f;
14 }
15 bool isroot(int k){return c[fa[k]][0]!=k&&c[fa[k]][1]!=k;}
16 void down(int x)
17 {
18     int l=c[x][0],r=c[x][1];
19     if(rev[x]){rev[x]^=1;rev[l]^=1;rev[r]^=1;swap(c[x][0],c[x][1]);}
20 }
21 void rotate(int x)
22 {
23     int y=fa[x],z=fa[y],l,r;
24     if(c[y][0]==x)l=0;else l=1;r=l^1;
25     if(!isroot(y)){if(c[z][0]==y)c[z][0]=x;else c[z][1]=x;}
26     fa[x]=z;fa[y]=x;fa[c[x][r]]=y;
27     c[y][l]=c[x][r];c[x][r]=y;
28 }
29 void splay(int x)
30 {
31     int top=0;st[++top]=x;
32     for(int i=x;!isroot(i);i=fa[i])st[++top]=fa[i];
33     for(int i=top;i;i--)down(st[i]);
34     while(!isroot(x))
35     {
36         int y=fa[x],z=fa[y];
37         if(!isroot(y))
38         {
39             if((c[y][0]==x)^(c[z][0]==y))rotate(x);
40             else rotate(y);
41         }
42         rotate(x);
43     }
44 }
45 void acs(int x){int t=0; while(x){splay(x);c[x][1]=t;t=x;x=fa[x];} }
46 void mkroot(int x){acs(x);splay(x);rev[x]^=1;}
48 void cut(int x,int y){mkroot(x);acs(y);splay(y);c[y][0]=fa[x]=0;}
49 int find(int x){acs(x);splay(x);while(c[x][0])x=c[x][0];return x;}
50 int main()
51 {
52     char s[15];
54     while(m--)
55     {
66 }