bzoj 2049 LCT模板
来源:互联网 发布:淘宝旺旺手机版卖家版 编辑:程序博客网 时间:2024/05/22 01:25
题意:初始n个点独立,三种操作:(1)Connect x y x和y之间连一条边 (2)Destroy x y x和y之间的边断掉 (3)Query x y 查询x和y是否联通
LCT模板..
var n,m,x,y :longint; i,j :longint; ch :char; s :string; father :array[-1..200010] of longint; son :array[-1..200010,0..1] of longint; flag :array[-1..200010] of boolean;function root(x:longint):boolean;begin if (x=son[father[x],0]) or (x=son[father[x],1]) then exit(false); exit(true);end;procedure swap(var a,b:longint);var c:longint;begin c:=a; a:=b; b:=c;end;procedure renew(x:longint);begin flag[x]:=not flag[x];end;procedure pushdown(x:longint);var l,r:longint;begin if flag[x] then begin swap(son[x,0],son[x,1]); l:=son[x,0]; r:=son[x,1]; flag[l]:=not flag[l]; flag[r]:=not flag[r]; end; flag[x]:=false;end;procedure push(x:longint);begin if not root(x) then push(father[x]); pushdown(x);end;procedure ro(x,y:longint);var f:longint;begin f:=father[x]; if son[x,y xor 1]<>-1 then father[son[x,y xor 1]]:=f; son[f,y]:=son[x,y xor 1]; if f=son[father[f],0] then son[father[f],0]:=x else if f=son[father[f],1] then son[father[f],1]:=x; father[x]:=father[f]; father[f]:=x; son[x,y xor 1]:=f;end;procedure splay(x:longint);var u,v:longint;begin while not root(x) do begin if root(father[x]) then ro(x,ord(x=son[father[x],1])) else begin if x=son[father[x],0] then u:=1 else u:=-1; if father[x]=son[father[father[x]],0] then v:=1 else v:=-1; if u*v=1 then begin ro(father[x],ord(x=son[father[x],1])); ro(x,ord(x=son[father[x],1])); end else begin ro(x,ord(x=son[father[x],1])); ro(x,ord(x=son[father[x],1])); end; end; end;end;procedure access(x:longint);var y:longint;begin y:=-1; while x<>0 do begin push(x); splay(x); son[x,1]:=y; y:=x; x:=father[x]; end;end;function find_root(x:longint):longint;begin access(x); splay(x); while (son[x,0]<>-1) do x:=son[x,0]; exit(x);end;begin read(n,m);readln; fillchar(son,sizeof(son),255); for i:=1 to m do begin s:=''; read(ch); while (ch<>' ') do begin s:=s+ch;read(ch); end; readln(x,y); if s='Connect' then begin access(x); splay(x); renew(x); access(y); son[y,1]:=x; father[x]:=y; end else if s='Destroy' then begin access(x); splay(x); renew(x); access(y); push(x); splay(x); son[x,1]:=-1; father[y]:=0; end else begin if find_root(x)=find_root(y) then writeln('Yes') else writeln('No'); end; end;end.——by Eirlys
0 0
- bzoj 2049 LCT模板
- BZOJ 2049 洞穴勘测 (LCT 模板)
- bzoj 2843 LCT模板
- BZOJ 2716 LCT模板题
- bzoj 2049: [Sdoi2008]Cave 洞穴勘测(LCT模板)
- 【BZOJ 2049】[Sdoi2008]Cave 洞穴勘测 LCT模板
- BZOJ 2049 LCT
- BZOJ 2049([Sdoi2008]Cave 洞穴勘测-LCT)[Template:LCT]
- bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊 lct模板
- lct模板
- LCT模板
- LCT模板
- 【模板】LCT
- 【模板】LCT
- LCT模板
- BZOJ 2049: [Sdoi2008]Cave 洞穴勘测 LCT
- BZOJ 2049 [Sdoi2008]Cave 洞穴勘测 LCT
- lct (bzoj 2049 Cave 洞穴勘测)
- opensuse42.1安装hotshots
- 硬币翻转问题
- mysql连接提示“登录出现1130 is not allowed to connect to this MySql server,解决方法
- Android 状态栏操作,你想知道的都在这里了 中宏
- python的多线程
- bzoj 2049 LCT模板
- 【数据结构 _双向链表_List_0960】双向链表的操作问题
- beef自动化攻击(5)
- Openlayers3 加载 GeoServer WMS的实现
- 计算机网络基本概念1
- 使用 logger 在脚本中输出多个日志
- JavaScript 逻辑中断(hack技巧-处理函数的默认参数/早期浏览器兼容处理)
- 跟着TensorFlow的进阶级教程实现MNIST库的训练
- 分词统计(一)使用讯飞语言云进行统计