BZOJ2049 LCT
来源:互联网 发布:mysql的日期转换函数 编辑:程序博客网 时间:2024/06/05 09:08
换了一种新写法,感觉比之前好
主要注意define Rotate()别写错
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<iostream>#define For(i,j,k) for(register int i=(j);i<=(int)k;i++)#define Forr(i,j,k) for(register int i=(j);i>=(int)k;i++)#define F(i) (T[i].fa)#define L(i) (T[i].s[0])#define R(i) (T[i].s[1])#define Loc(i) (i==R(F(i)))#define Set(a,b) memset((a),(b),sizeof(a))using namespace std;const int N=10010;inline void read(int &x){ x=0;char c=getchar();int f=(c=='-'); while(c<'0'||c>'9')c=getchar(),f|=(c=='-'); while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();if(f)x=-x;}struct node{ int s[2],rev,fa;};struct LCT{ node T[N]; inline void clear(){Set(T,0);} inline void pushdown(int x){ if(T[x].rev){ T[x].rev^=1,T[L(x)].rev^=1,T[R(x)].rev^=1; swap(L(x),R(x)); } } inline bool isrt(int x){ return L(F(x))!=x&&R(F(x))!=x; } void Pushdown(int x){ if(!isrt(x))Pushdown(F(x)); pushdown(x); } inline void Sets(int a,int b,int c){ T[a].s[c]=b,F(b)=a; } void Rotate(int x){ int y=F(x),z=F(y),l=Loc(x),r=l^1; if(!isrt(y))T[z].s[Loc(y)]=x;F(x)=z; Sets(y,T[x].s[r],l); Sets(x,y,r); } inline void splay(int x){ Pushdown(x); while(!isrt(x)){ int y=F(x),z=F(y); if(!isrt(y))Rotate(x); Rotate(x); } } inline void access(int x){ int y=0; while(x){ splay(x); R(x)=y; y=x,x=F(x); } } inline int findrt(int x){ access(x);splay(x); while(L(x))x=L(x); return x; } inline void reverse(int x){ access(x); splay(x); T[x].rev^=1; } inline void link(int x,int y){ reverse(x),F(x)=y,splay(x); } inline void cut(int x,int y){ reverse(x),access(y),splay(y),F(x)=L(y)=0; }}t;char s[10];int main(){ int n,m,x,y; t.clear(); read(n),read(m); For(i,1,m){ scanf("%s",s);read(x),read(y); if(s[0]=='C')t.link(x,y); else if (s[0]=='D')t.cut(x,y); else { if(t.findrt(x)==t.findrt(y))puts("Yes"); else puts("No"); } } return 0;}
0 0
- bzoj2049 LCT
- BZOJ2049 LCT
- LCT(模板题)BZOJ2049
- bzoj2049 洞穴勘测 lct
- BZOJ2049 洞穴勘测 LCT
- bzoj2049(lct)
- 【bzoj2049】【LCT】洞穴勘测
- bzoj2049 [ SDOI2008 ] -- LCT
- 【bzoj2049】【SDOI2008】【洞穴勘测】【lct】
- 【bzoj2049】Cave洞穴勘测 LCT
- [bzoj2049][LCT]洞穴探测cave
- bzoj2049 洞穴勘探【LCT模板】
- bzoj2049: [Sdoi2008]Cave 洞穴勘测 LCT
- 【LCT】BZOJ2049[Sdoi2008]Cave 洞穴勘测
- bzoj2049[洞穴勘测]纯粹的LCT
- [BZOJ2049][SDOI2008]Cave 洞穴勘测(LCT)
- 【BZOJ2049】【codevs1839】洞穴探测,LCT练习
- [BZOJ2049][[Sdoi2008]Cave 洞穴勘测][LCT]
- MatConvnet--CNN wrappers
- ansible 配置使用
- 编程错误提示 无法打开头文件
- 代码实现补间动画
- Java数据类型和MySql数据类型对应描述
- BZOJ2049 LCT
- 抽象类、接口的简单语法
- 利用php发送邮件
- php之redis笔记1
- react native常见的错误
- 为什么c++支持重载而C语言不支持重载
- 一道快速排序题的解析
- RecyclerView监听
- SpringMVC参数绑定高级