# [bzoj4229][动态树]选择

4229: 选择

Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 100 Solved: 59
[Submit][Status][Discuss]
Description

1、删除某一条图上仍存在的边
2、询问是否存在两条边不相交的路径可以从点u出发到点v
Input

Output

Sample Input

7 8 7

1 2

1 3

1 4

2 3

3 4

3 7

7 4

5 6

Z 1 4

P 1 3

P 2 4

Z 1 3

P 1 3

Z 6 5

P 5 6
Sample Output

Yes

Yes

No

No
HINT

Source

[Submit][Status][Discuss]
﻿

## sol:

#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
using namespace std;

inline int read()
{
char c;
bool pd=0;
while((c=getchar())>'9'||c<'0')
if(c=='-') pd=1;
int res=c-'0';
while((c=getchar())>='0'&&c<='9')
res=(res<<3)+(res<<1)+c-'0';
return pd?-res:res;
}
const int N=110000;
int rev[N],lc[N],rc[N],fa[N],father[N];
inline int find(int x)
{
return x==father[x]?x:father[x]=find(father[x]);
}
inline void tag_rev(int x)
{
rev[x]=!rev[x];
swap(lc[x],rc[x]);
}
inline void tag_down(int x)
{
if(rev[x])
{
rev[x]=0;
tag_rev(lc[x]);
tag_rev(rc[x]);
}
}
inline void rotate(int x)
{
int y=fa[x],z=fa[y];
int b=lc[y]==x?rc[x]:lc[x];
if(b) fa[b]=y;
fa[y]=x;fa[x]=z;
if(z)
{
if(lc[z]==y) lc[z]=x;
if(rc[z]==y) rc[z]=x;
}
if(lc[y]==x) lc[y]=b,rc[x]=y;
else rc[y]=b,lc[x]=y;
}
int sta[N];
inline bool is_root(int x)
{
return lc[fa[x]]!=x&&rc[fa[x]]!=x;
}
inline void splay(int x)
{
sta[sta[0]=1]=x;
for(int y=x;!is_root(y);y=fa[y])
{
fa[y]=find(fa[y]);
sta[++sta[0]]=fa[y];
}
while(sta[0]) tag_down(sta[sta[0]--]);
while(!is_root(x))
{
fa[x]=find(fa[x]);
if(!is_root(fa[x]))
{
fa[fa[x]]=find(fa[fa[x]]);
if((lc[fa[fa[x]]]==fa[x])==(lc[fa[x]]==x)) rotate(fa[x]);
else rotate(x);
}
rotate(x);
}
}
inline void access(int q)
{
for(int p=0;q;p=q,q=fa[q])
{
splay(q);
rc[q]=p;
fa[q]=find(fa[q]);
}
}
inline void make_root(int x)
{
access(x);
splay(x);
tag_rev(x);
}
inline void sc(int x,int y)
{
if(!x) return;
father[x]=y;
if(lc[x]) sc(lc[x],y);
if(rc[x]) sc(rc[x],y);
}
inline void link(int x,int y)
{
make_root(x);
fa[x]=y;
}
inline int find_root(int x)
{
access(x);
splay(x);
tag_down(x);
while(lc[x])
{
x=lc[x];
tag_down(x);
}
return x;
}
inline void add(int x,int y)
{
x=find(x);y=find(y);
if(x==y) return;
if(find_root(x)==find_root(y))
{
make_root(x);
access(y);
splay(x);
sc(x,find(x));
return;
}
link(x,y);
}
int n,m,q;
char sr[5];
struct cc
{
int x,y,z;
}a[N],b[N];
map<int,bool> ex[N];
int ans[N];
int main()
{
//  freopen("4229.in","r",stdin);
n=read();
m=read();
q=read();
for(int i=1;i<=n;++i) father[i]=i;
for(int i=1;i<=m;++i)
{
b[i].x=read();
b[i].y=read();
}
int x,y;
for(int i=1;i<=q;++i)
{
scanf("%s",sr+1);
if(sr[1]=='P') a[i].z=1;
a[i].x=read();
a[i].y=read();
if(!a[i].z) ex[a[i].x][a[i].y]=ex[a[i].y][a[i].x]=1;
}
for(int i=1;i<=m;++i)
if(!ex[b[i].x][b[i].y])
add(b[i].x,b[i].y);

for(int i=q;i>=1;--i)
{
if(a[i].z)
{
if(find(a[i].x)==find(a[i].y)) ans[i]=1;
}
else add(a[i].x,a[i].y);
}
for(int i=1;i<=q;++i)
if(a[i].z) puts(ans[i]?"Yes":"No");
}