题意:有一张图,每条边有一个不同的编号,长度和权值,维护以下操作:

1.加边

2.修改边长

3.询问两点之间在最小权值最大的前提下的唯一路径长度

n<=100000 m<=300000

思路:RYZ作业

BZOJ上有四组数据的输入不完整,输出没问题

LCT维护最大生成树,维护子树和,和子树中权值最小的位置即可

 var t:array[..,..]of longint;
sum:array[..]of int64;
f:array[..,..]of longint;
w,l1,mx,fa,q,rev:array[..]of longint;
n,m,x,y,top,tot,id,i,len,s,ll,tt,j,tmp,now:longint;
ch:string; procedure swap(var x,y:longint);
var t:longint;
begin
t:=x; x:=y; y:=t;
end; function isroot(x:longint):boolean;
begin
if (t[fa[x],]<>x)and(t[fa[x],]<>x) then exit(true);
exit(false);
end; procedure pushup(x:longint);
var l,r:longint;
begin
l:=t[x,]; r:=t[x,];
sum[x]:=sum[l]+sum[r]+l1[x];
mx[x]:=x;
if w[mx[l]]<w[mx[x]] then mx[x]:=mx[l];
if w[mx[r]]<w[mx[x]] then mx[x]:=mx[r];
end; procedure pushdown(x:longint);
var l,r:longint;
begin
l:=t[x,]; r:=t[x,];
if rev[x]> then
begin
rev[x]:=rev[x] xor ; rev[l]:=rev[l] xor ; rev[r]:=rev[r] xor ;
swap(t[x,],t[x,]);
end;
end; procedure rotate(x:longint);
var y,z,l,r:longint;
begin
y:=fa[x]; z:=fa[y];
if t[y,]=x then l:=
else l:=;
r:=l xor ;
if not isroot(y) then
begin
if t[z,]=y then t[z,]:=x
else t[z,]:=x;
end;
fa[y]:=x; fa[x]:=z; fa[t[x,r]]:=y;
t[y,l]:=t[x,r]; t[x,r]:=y;
pushup(y);
pushup(x);
end; procedure splay(x:longint);
var k,y,z:longint;
begin
inc(top); q[top]:=x;
k:=x;
while not isroot(k) do
begin
inc(top); q[top]:=fa[k];
k:=fa[k];
end;
while top> do
begin
pushdown(q[top]);
dec(top);
end; while not isroot(x) do
begin
y:=fa[x]; z:=fa[x];
if not isroot(y) then
begin
if (t[y,]=x)xor(t[z,]=y) then rotate(x)
else rotate(y);
end;
rotate(x);
end;
end; procedure access(x:longint);
var last:longint;
begin
last:=;
while x> do
begin
splay(x); t[x,]:=last; pushup(x);
last:=x; x:=fa[x];
end;
end; procedure makeroot(x:longint);
begin
access(x); splay(x); rev[x]:=rev[x] xor ;
end; procedure link(x,y:longint);
begin
makeroot(x); fa[x]:=y;
end; procedure split(x,y:longint);
begin
makeroot(x); access(y); splay(y);
end; procedure cut(x,y:longint);
begin
makeroot(x); access(y); splay(y); t[y,]:=; fa[x]:=;
end; function findroot(x:longint):longint;
var k:longint;
begin
access(x); splay(x);
k:=x;
while t[k,]<> do k:=t[k,];
exit(k);
end; begin
assign(input,'bzoj4736.in'); reset(input);
assign(output,'bzoj4736.out'); rewrite(output);
readln(n,m);
fillchar(w,sizeof(w),$7f);
//fillchar(l,sizeof(l),$1f);
for i:= to m do
begin
readln(ch); s:=; id:=; x:=; y:=; tt:=; ll:=;
len:=length(ch);
case ch[] of
'f':
begin
for j:= to len do
begin
if ch[j]=' ' then begin inc(s); continue; end;
tmp:=ord(ch[j])-ord('');
case s of
:id:=id*+tmp;
:x:=x*+tmp;
:y:=y*+tmp;
:tt:=tt*+tmp;
:ll:=ll*+tmp;
end;
end;
inc(x); inc(y); inc(id);
tot:=id+;
w[tot]:=tt; l1[tot]:=ll; f[tot,]:=x; f[tot,]:=y;
if findroot(x)<>findroot(y) then
begin
mx[tot]:=tot;
link(x,tot); link(tot,y);
end
else
begin
split(x,y);
now:=mx[y];
if w[now]<tt then
begin
cut(f[now,],now); cut(now,f[now,]);
mx[tot]:=tot;
link(x,tot); link(tot,y);
end;
end; end;
'm':
begin
for j:= to len do
begin
if ch[j]=' ' then begin inc(s); continue; end;
tmp:=ord(ch[j])-ord('');
case s of
:x:=x*+tmp;
:y:=y*+tmp;
end;
end;
inc(x); inc(y);
if findroot(x)<>findroot(y) then writeln(-)
else
begin
split(x,y); writeln(sum[y]);
end;
end;
'c':
begin
for j:= to len do
begin
if ch[j]=' ' then begin inc(s); continue; end;
tmp:=ord(ch[j])-ord('');
case s of
:id:=id*+tmp;
:ll:=ll*+tmp;
end;
end;
inc(id); tot:=id+;
splay(tot);
l1[tot]:=ll;
pushup(tot);
end;
end;
end;
close(input);
close(output);
end.

2017.3.9

突然发现前一个代码splay打错了一个字母导致退化成类似单旋的东西

神TM单旋也能过

 var t:array[..,..]of longint;
sum:array[..]of int64;
f:array[..,..]of longint;
w,l1,mx,fa,q,rev:array[..]of longint;
n,m,x,y,top,tot,id,i,len,s,ll,tt,j,tmp,now:longint;
ch:string; procedure swap(var x,y:longint);
var t:longint;
begin
t:=x; x:=y; y:=t;
end; function isroot(x:longint):boolean;
begin
if (t[fa[x],]<>x)and(t[fa[x],]<>x) then exit(true);
exit(false);
end; procedure pushup(x:longint);
var l,r:longint;
begin
l:=t[x,]; r:=t[x,];
sum[x]:=sum[l]+sum[r]+l1[x];
mx[x]:=x;
if w[mx[l]]<w[mx[x]] then mx[x]:=mx[l];
if w[mx[r]]<w[mx[x]] then mx[x]:=mx[r];
end; procedure pushdown(x:longint);
var l,r:longint;
begin
l:=t[x,]; r:=t[x,];
if rev[x]> then
begin
rev[x]:=rev[x] xor ; rev[l]:=rev[l] xor ; rev[r]:=rev[r] xor ;
swap(t[x,],t[x,]);
end;
end; procedure rotate(x:longint);
var y,z,l,r:longint;
begin
y:=fa[x]; z:=fa[y];
if t[y,]=x then l:=
else l:=;
r:=l xor ;
if not isroot(y) then
begin
if t[z,]=y then t[z,]:=x
else t[z,]:=x;
end;
fa[y]:=x; fa[x]:=z; fa[t[x,r]]:=y;
t[y,l]:=t[x,r]; t[x,r]:=y;
pushup(y);
pushup(x);
end; procedure splay(x:longint);
var k,y,z:longint;
begin
inc(top); q[top]:=x;
k:=x;
while not isroot(k) do
begin
inc(top); q[top]:=fa[k];
k:=fa[k];
end;
while top> do
begin
pushdown(q[top]);
dec(top);
end; while not isroot(x) do
begin
y:=fa[x]; z:=fa[y];
if not isroot(y) then
begin
if (t[y,]=x)xor(t[z,]=y) then rotate(x)
else rotate(y);
end;
rotate(x);
end;
end; procedure access(x:longint);
var last:longint;
begin
last:=;
while x> do
begin
splay(x); t[x,]:=last; pushup(x);
last:=x; x:=fa[x];
end;
end; procedure makeroot(x:longint);
begin
access(x); splay(x); rev[x]:=rev[x] xor ;
end; procedure link(x,y:longint);
begin
makeroot(x); fa[x]:=y;
end; procedure split(x,y:longint);
begin
makeroot(x); access(y); splay(y);
end; procedure cut(x,y:longint);
begin
makeroot(x); access(y); splay(y); t[y,]:=; fa[x]:=;
end; function findroot(x:longint):longint;
var k:longint;
begin
access(x); splay(x);
k:=x;
while t[k,]<> do k:=t[k,];
exit(k);
end; begin
assign(input,'bzoj4736.in'); reset(input);
assign(output,'bzoj4736.out'); rewrite(output);
readln(n,m);
fillchar(w,sizeof(w),$7f);
//fillchar(l,sizeof(l),$1f);
for i:= to m do
begin
readln(ch); s:=; id:=; x:=; y:=; tt:=; ll:=;
len:=length(ch);
case ch[] of
'f':
begin
for j:= to len do
begin
if ch[j]=' ' then begin inc(s); continue; end;
tmp:=ord(ch[j])-ord('');
case s of
:id:=id*+tmp;
:x:=x*+tmp;
:y:=y*+tmp;
:tt:=tt*+tmp;
:ll:=ll*+tmp;
end;
end;
inc(x); inc(y); inc(id);
tot:=id+;
w[tot]:=tt; l1[tot]:=ll; f[tot,]:=x; f[tot,]:=y;
if findroot(x)<>findroot(y) then
begin
mx[tot]:=tot;
link(x,tot); link(tot,y);
end
else
begin
split(x,y);
now:=mx[y];
if w[now]<tt then
begin
cut(f[now,],now); cut(now,f[now,]);
mx[tot]:=tot;
link(x,tot); link(tot,y);
end;
end; end;
'm':
begin
for j:= to len do
begin
if ch[j]=' ' then begin inc(s); continue; end;
tmp:=ord(ch[j])-ord('');
case s of
:x:=x*+tmp;
:y:=y*+tmp;
end;
end;
inc(x); inc(y);
if findroot(x)<>findroot(y) then writeln(-)
else
begin
split(x,y); writeln(sum[y]);
end;
end;
'c':
begin
for j:= to len do
begin
if ch[j]=' ' then begin inc(s); continue; end;
tmp:=ord(ch[j])-ord('');
case s of
:id:=id*+tmp;
:ll:=ll*+tmp;
end;
end;
inc(id); tot:=id+;
splay(tot);
l1[tot]:=ll;
pushup(tot);
end;
end;
end;
close(input);
close(output);
end.

【BZOJ4736】温暖会指引我们前行(LCT)的更多相关文章

  1. UOJ #274. 【清华集训2016】温暖会指引我们前行 [lct]

    #274. [清华集训2016]温暖会指引我们前行 题意比较巧妙 裸lct维护最大生成树 #include <iostream> #include <cstdio> #incl ...

  2. 【UOJ274】【清华集训2016】温暖会指引我们前行 LCT

    [UOJ274][清华集训2016]温暖会指引我们前行 任务描述 虽然小R住的宿舍楼早已来了暖气,但是由于某些原因,宿舍楼中的某些窗户仍然开着(例如厕所的窗户),这就使得宿舍楼中有一些路上的温度还是很 ...

  3. bzoj 4736 /uoj274【清华集训2016】温暖会指引我们前行 lct

    [清华集训2016]温暖会指引我们前行 统计 描述 提交 自定义测试 寒冬又一次肆虐了北国大地 无情的北风穿透了人们御寒的衣物 可怜虫们在冬夜中发出无助的哀嚎 “冻死宝宝了!” 这时 远处的天边出现了 ...

  4. [清华集训2016]温暖会指引我们前行——LCT+最大生成树

    题目链接: [清华集训2016]温暖会指引我们前行 题目大意:有$n$个点$m$次操作,每次操作分为三种:1.在$u,v$两点之间连接一条编号为$id$,长度为$l$,温度为$t$的边.2.查询从$u ...

  5. BZOJ4736 温暖会指引我们前行(LCT+最大生成树)

    类似于瓶颈路,满足条件的路径一定在温度的最大生成树上,那么就是一个LCT维护MST的裸题了. #include<iostream> #include<cstdio> #incl ...

  6. [BZOJ4736]温暖会指引我们前行

    BZOJ(BZOJ上的是什么鬼...) UOJ 任务描述 虽然小R住的宿舍楼早已来了暖气,但是由于某些原因,宿舍楼中的某些窗户仍然开着(例如厕所的窗户),这就使得宿舍楼中有一些路上的温度还是很低. 小 ...

  7. BZOJ 4736 温暖会指引我们前行 LCT+最优生成树+并查集

    题目链接:http://uoj.ac/problem/274 题意概述: 没什么好概述的......概述了题意就知道怎么做了......我懒嘛 分析: 就是用lct维护最大生成树. 然后如果去UOJ上 ...

  8. Uoj #274. 【清华集训2016】温暖会指引我们前行 LCT维护边权_动态最小生成树

    Code: 行#include<bits/stdc++.h> #define ll long long #define maxn 1000000 #define inf 100000000 ...

  9. 【BZOJ4736】温暖会指引我们前行(Link-Cut Tree)

    [BZOJ4736]温暖会指引我们前行(Link-Cut Tree) ##题面 神TM题面是UOJ的 题解 LCT傻逼维护最大生成树 不会的可以去做一做魔法森林 #include<iostrea ...

  10. UOJ_274_[清华集训2016]温暖会指引我们前行_LCT

    UOJ_274_[清华集训2016]温暖会指引我们前行_LCT 任务描述:http://uoj.ac/problem/274 本题中的字典序不同在于空串的字典序最大. 并且题中要求排序后字典序最大. ...

随机推荐

  1. 在js中怎样获得checkbox里选中的多个值?(jQuery)

    思路:利用name属性值获取checkbox对象,然后循环判断checked属性(true表示被选中,false表示未选中).下面进行实例演示: 1.HTML结构 <input type=&qu ...

  2. phpstorm设置代码块快捷方式

    File -> Settings -> Live Templates

  3. qt5.8+vs2015使用Qt5WebEngine搭建环境

    转载请注明出处:http://www.cnblogs.com/dachen408/p/7575094.html 1.项目属性,C/C++,所有选项,附加包含目录新增. $(QTDIR)\include ...

  4. http接口调用,传递json格式带双引号问题

    springmvc 配置好会自动转换json格式,只要配置他转格式之前,在转次String类型就好

  5. 洛谷 P2912 [USACO08OCT]牧场散步Pasture Walking

    题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures ...

  6. SAP CRM点了附件的超链接后报错的处理方式

    SAP CRM系统里,点击了附件的这些超链接后,如果是文本文件,会在浏览器里打开.如果是其他类型的文件,会弹出下载对话框. 然而最近我工作时遇到一个问题,点击超链接后,总是弹出Logon failed ...

  7. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 忘记mysql密码

    [root@mysql-db03 ~]# mysql -uroot -poldboy123Warning: Using a password on the command line interface ...

  8. (转)Spring4.2.5+Hibernate4.3.11+Struts2.3.24整合开发

    http://blog.csdn.net/yerenyuan_pku/article/details/52902851 前面我们已经学会了Spring4.2.5+Hibernate4.3.11+Str ...

  9. PyTorch如何构建深度学习模型?

    简介 每过一段时间,就会有一个深度学习库被开发,这些深度学习库往往可以改变深度学习领域的景观.Pytorch就是这样一个库. 在过去的一段时间里,我研究了Pytorch,我惊叹于它的操作简易.Pyto ...

  10. Word转html并移植到web项目

    1.打开对应word文件 建议使用web视图查看文档 这样可以提前预览转转成html样式 2.如果有图片修改图片大小及格式 在web视图下,把图片调制适当大小,不然导出的html可能图片较小 3.点击 ...