BZOJ 2049 Cave 洞穴勘测 [LCT]
来源:互联网 发布:sha1 js 时间 编辑:程序博客网 时间:2024/05/21 15:00
LCT模板裸题,pushdown要注意,Splay练手。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>const int N = 200110;const int INF = 0x3f3f3f3f;using namespace std;inline void read(int &res){ register int flag=1;static char ch; while((ch=getchar())<'0'||ch>'9')if(ch=='-')flag=-1;res=ch-48; while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;res*=flag;}int n,m,fa[N],c[N][2],st[N];bool rev[N];char cmd[10];inline bool isroot(int x){ return c[fa[x]][0]!=x&&c[fa[x]][1]!=x;}inline void pushdown(int x){ register int l=c[x][0],r=c[x][1]; if(rev[x]){ rev[x]^=1;rev[l]^=1;rev[r]^=1; swap(c[x][0],c[x][1]); }}inline void rotate(int x){ register int y=fa[x],z=fa[y],l,r; if(c[y][0]==x)l=0; else l=1;r=l^1; if(!isroot(y)){ if(c[z][0]==y)c[z][0]=x; else c[z][1]=x; } fa[x]=z;fa[y]=x;fa[c[x][r]]=y; c[y][l]=c[x][r];c[x][r]=y;}inline void splay(int x){ register int top=0;st[++top]=x; for(register int i=x;!isroot(i);i=fa[i]){ st[++top]=fa[i]; } for(register int i=top;i;i--)pushdown(st[i]); while(!isroot(x)){ register int y=fa[x],z=fa[y]; if(!isroot(y)){ if(c[y][0]==x^c[z][0]==y)rotate(x); else rotate(y); } rotate(x); }}inline void access(int x){ register int t=0; while(x){ splay(x); c[x][1]=t; t=x;x=fa[x]; }}inline void rever(int x){ access(x);splay(x);rev[x]^=1;}inline void link(int x,int y){ rever(x);fa[x]=y;splay(x);}inline void cut(int x,int y){ rever(x);access(y);splay(y);c[y][0]=fa[x]=0;}inline int find(int x){ access(x);splay(x); register int y=x; while(c[y][0])y=c[y][0]; return y;}int main(){ read(n),read(m); for(register int x,y,i=1;i<=m;i++){ scanf("%s",cmd),read(x),read(y); if(cmd[0]=='C')link(x,y); else if(cmd[0]=='D')cut(x,y); else if(find(x)==find(y))printf("Yes\n"); else printf("No\n"); } return 0;}
阅读全文
0 0
- BZOJ 2049: [Sdoi2008]Cave 洞穴勘测 LCT
- BZOJ 2049 [Sdoi2008]Cave 洞穴勘测 LCT
- lct (bzoj 2049 Cave 洞穴勘测)
- 【LCT】BZOJ 2049:[Sdoi2008]Cave洞穴勘测
- Bzoj 2049: [Sdoi2008]Cave 洞穴勘测(LCT)
- BZOJ 2049: [Sdoi2008]Cave 洞穴勘测(LCT)
- LCT(Cave 洞穴勘测,BZOJ 2049)
- BZOJ 2049 Cave 洞穴勘测 [LCT]
- BZOJ-2049 Cave 洞穴勘测(LCT)
- bzoj 2049 [Sdoi2008]Cave 洞穴勘测 LCT
- BZOJ 2049([Sdoi2008]Cave 洞穴勘测-LCT)[Template:LCT]
- 【BZOJ】2049 [Sdoi2008]Cave 洞穴勘测 LCT入门题
- 【LCT】【SDOI 2008】【bzoj 2049】Cave 洞穴勘测
- bzoj 2049: [Sdoi2008]Cave 洞穴勘测(LCT模板)
- 【BZOJ 2049】[Sdoi2008]Cave 洞穴勘测 LCT模板
- BZOJ 2049 Cave 洞穴勘测(LCT动态树)
- BZOJ 2049: [Sdoi2008]Cave 洞穴勘测 LCT題解
- bzoj-2049 Cave 洞穴勘测
- Eclipse R语言插件 statET 安装
- iOS10富文本推送--UIMutableUserNotificationAction
- Android启动一个新的activity并携带数据,返回数据给上一个activity
- Android中checkbox控件的自定义样式设置
- 防止头文件的重复包含
- BZOJ 2049 Cave 洞穴勘测 [LCT]
- PHP与 RESTful风格的swagger结合生成API
- 当你完不成自己的程序时,就不要睡觉......
- mybatis进阶(5)--多对多查询
- centos7.2 安装hdp2.6.1.0
- iOS10富文本推送--NotificationServiceExtension
- POJ 3895 Cycles of Lanes(dfs+模拟)
- codeforces830B Cards Sorting -- 线段树
- 前端笔记——html(1)