#include<iostream>
#include<cstring>
#include<cstdio>
#define LL long long
using namespace std;
int f[],c[][],st[];
bool r[];
#define l(x) c[x][0]
#define r(x) c[x][1]
inline bool nroot(int x){return c[f[x]][]==x||c[f[x]][]==x;}
void pushup(int x){;}
void pushr(int x){int t=l(x);l(x)=r(x);r(x)=t;r[x]^=;}
void pushdown(int x)
{
if(!r[x])return;
if(l(x))pushr(l(x));
if(r(x))pushr(r(x));
r[x]=;
}
void rotate(int x)//
{
int y=f[x],z=f[y],k=r(y)==x,w=c[x][!k];
if(nroot(y))c[z][r(z)==y]=x;c[x][!k]=y;c[y][k]=w;
if(w)f[w]=y;f[y]=x;f[x]=z;
pushup(y);
}
void splay(int x)//
{
int y=x,z=;st[++z]=y;
while(nroot(y))st[++z]=y=f[y];
while(z)pushdown(st[z--]);
while(nroot(x))
{
y=f[x];z=f[y];
if(nroot(y))rotate((l(y)==x)^(l(z)==y)?x:y);
rotate(x);
}
pushup(x);
}
void access(int x){for(int y=;x;x=f[y=x])splay(x),r(x)=y,pushup(x);}//
void makeroot(int x){access(x);splay(x);pushr(x);}//
int findroot(int x){access(x);splay(x);while(l(x))pushdown(x),x=l(x);splay(x);return x;}//
void split(int x,int y){makeroot(x);access(y);splay(y);}//
void link(int x,int y){makeroot(x);if(findroot(y)!=x)f[x]=y;}//
void cut(int x,int y)
{
makeroot(x);
if(findroot(y)==x&&f[y]==x&&!l(y))
f[y]=r(x)=,pushup(x);
}
int n,m;
signed main()
{
cin>>n>>m;
char opt[];int u,v;
for(int i=;i<=m;i++)
{
cin>>opt;
if(opt[]=='C')cin>>u>>v,link(u,v);
if(opt[]=='D')cin>>u>>v,cut(u,v);
if(opt[]=='Q')
{
cin>>u>>v;
if(findroot(u)==findroot(v))puts("Yes");
else puts("No");
}
}
}

最新文章

  1. 1Z0-053 争议题目解析481
  2. String split
  3. php版本引起的const问题
  4. Redis 存储原理
  5. android Service Activity交互之传递复杂数据类型的远程服务
  6. NENU_CS_segment_tree
  7. java.util.TreeSet源码分析
  8. DevExpress的 ASPxGridview控件的自动配置效果
  9. C#实现MySQL数据库中的blob数据存储
  10. 字符编码终极笔记:ASCII、Unicode、UTF-8、UTF-16、UCS、BOM、Endian
  11. Hashtable 小记
  12. python+flask 分分钟完美解析阿里云日志
  13. vue父子组件生命周期执行顺序
  14. 2072. Kirill the Gardener 3
  15. [android] 表格布局和绝对布局
  16. TXB0108 TXS0108E 8-Bit Bidirectional Voltage-Level Translator for Open-Drain and Push-Pull Applications
  17. vsm安装
  18. 移动设备&#160;小米2S不显示CD驱动器(H),便携设备,MTP,驱动USB&#160;Driver,MI2感叹号的解决方法
  19. eclipse启动一闪而退
  20. jquery 判断checkbox状态

热门文章

  1. Browsersync 浏览器自动刷新
  2. js中的定义变量之①用不用var
  3. webstorm格式化代码快捷键
  4. spring cloud深入学习(五)-----熔断器Hystrix
  5. Linux安装Desktop 和 vncserver
  6. How To Install Nginx on CentOS 7(转)
  7. Java过滤器—Filter用法简介
  8. POSTMAN调试接口post对象
  9. IO流8 --- 使用FileReader和FileWriter实现文本文件的复制 --- 技术搬运工(尚硅谷)
  10. python对dataframe的相关用法