## 2049: [Sdoi2008]Cave 洞穴勘测

Time Limit: 10 Sec   Memory Limit: 259 MB

Submit: 8714

Solved: 4143

[Submit][Status][Discuss]

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

Source

【分析】

LCT练手题...不过还是觉得LCT不可调...

【代码】

``````//[SDOI2008]Cave 洞穴勘测
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mxn=100005;
char s[10];
int n,m,top;
int f[mxn],ch[mxn][2],rev[mxn],size[mxn],st[mxn];
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return x*f;
}
inline bool isroot(int x)
{
return (ch[f[x]][0]!=x && ch[f[x]][1]!=x);
}
inline int get(int x)
{
if(ch[f[x]][0]==x) return 0;return 1;
}
inline void update(int x)
{
size[x]=size[ch[x][0]]+size[ch[x][1]]+1;
}
inline void pushdown(int x)
{
if(rev[x])
{
rev[ch[x][0]]^=1,rev[ch[x][1]]^=1;
swap(ch[x][0],ch[x][1]);
rev[x]=0;
}
}
inline void rotate(int x)
{
pushdown(x);
int fa=f[x],fafa=f[fa],which=get(x);
if(!isroot(fa)) ch[fafa][ch[fafa][1]==fa]=x;
f[x]=fafa;
ch[fa][which]=ch[x][which^1],f[ch[fa][which]]=fa;
ch[x][which^1]=fa,f[fa]=x;
update(fa),update(x);
}
inline void splay(int x)
{
st[top=1]=x;
for(int i=x;!isroot(i);i=f[i]) st[++top]=f[i];
for(int i=top;i;i--) pushdown(st[i]);
for(int fa;!isroot(x);rotate(x))
if(!isroot(fa=f[x])) rotate(get(x)==get(fa)?fa:x);
}
inline void access(int x)
{
for(int y=0;x;y=x,x=f[x])
splay(x),ch[x][1]=y;
}
inline void makeroot(int x)
{
access(x),splay(x),rev[x]^=1;
}
inline int find(int x)
{
access(x),splay(x);
while(ch[x][0]) x=ch[x][0];
return x;
}
{
makeroot(x);
f[x]=y,splay(x);
}
inline void cut(int x,int y)
{
makeroot(x);
access(y),splay(y);
f[x]=ch[y][0]=0;
}
int main()
{
int i,j,x,y;
char s[10];