# 算法复习——LCT（bzoj2049洞穴勘测）

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

LCT简单模版题;

## 代码：

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<cctype>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int N=2e6+5;
int n,m,u,v;
int son[N][2],father[N],tag[N],cnt,stack[N];
char s[15];
inline int get(int now)
{
return son[father[now]][1]==now;
}
inline void pushdown(int now)
{
if(tag[now]&&now)
{
swap(son[now][0],son[now][1]);
tag[son[now][0]]^=1;
tag[son[now][1]]^=1;
tag[now]=0;
}
}
inline bool isroot(int now)
{
if(!father[now])  return true;
else if(son[father[now]][1]!=now&&son[father[now]][0]!=now)  return true;
else return false;
}
inline void rotate(int now)
{
pushdown(father[now]),pushdown(now);
int fa=father[now],ofa=father[fa],which=get(now);
if(!isroot(fa))  son[ofa][son[ofa][1]==fa]=now;
son[fa][which]=son[now][which^1],father[son[fa][which]]=fa;
son[now][which^1]=fa,father[fa]=now,father[now]=ofa;
}
inline void splay(int now)
{
stack[cnt=0]=now;
for(int i=now;!isroot(i);i=father[i])
stack[++cnt]=father[i];
for(int i=cnt;i>=0;i--)
pushdown(stack[i]);
while(!isroot(now))
{
if(!isroot(father[now]))
rotate(get(father[now])==get(now)?father[now]:now);
rotate(now);
}
}
inline void access(int now)
{
int temp=0;
for(;now;temp=now,now=father[now])
splay(now),son[now][1]=temp;
}
inline int getroot(int now)
{
access(now);splay(now);
while(son[now][0])  now=son[now][0];
return now;
}
inline void makeroot(int now)
{
access(now);splay(now);tag[now]^=1;
}
{
makeroot(a);father[a]=b;
}
inline void cut(int a,int b)
{
makeroot(a);access(b);splay(b);
father[a]=son[b][0]=0;
}
int main()
{
//freopen("a.in","r",stdin);
scanf("%d%d",&n,&m);
while(m--)
{
scanf("%s%d%d",s,&u,&v);
if(s[0]=='Q')
{
if(getroot(u)==getroot(v))  printf("Yes\n");
else printf("No\n");
}
if(s[0]=='C')
}