题目分析:

差评,最大生成树裸题。hack数据还卡常。

代码:

 #include<bits/stdc++.h>
using namespace std; const int maxn = ; struct LCT{
int fa[maxn],lazy[maxn],ch[maxn][],d1[maxn],d2[maxn];
int val[maxn],tot[maxn],num;
stack<int> sta;
void push_up(int now){
val[now] = min(d1[now],min(val[ch[now][]],val[ch[now][]]));
tot[now] = d2[now] + tot[ch[now][]] + tot[ch[now][]];
}
void push_down(int now){
if(lazy[now]){
swap(ch[now][],ch[now][]);
lazy[now]=;
lazy[ch[now][]] ^= ; lazy[ch[now][]] ^= ;
lazy[] = ;
}
}
int is_root(int now){return !(ch[fa[now]][]==now||ch[fa[now]][]==now);}
void r0(int now,int dr){
int ff = fa[now],gf = fa[ff],son = ch[now][dr];
int flag = is_root(ff);
ch[ff][dr^] = son; fa[son] = ff;
ch[now][dr] = ff; fa[ff] = now;
fa[now] = gf;
if(!flag){if(ch[gf][] == ff) ch[gf][] = now; else ch[gf][] = now;}
push_up(ff); push_up(now);
fa[] = ;ch[][] = ch[][] = ;
}
void splay(int now){
int pp = now;
while(!is_root(pp)) sta.push(pp),pp = fa[pp];
sta.push(pp);
while(!sta.empty()) push_down(sta.top()),sta.pop();
while(!is_root(now)){
if(is_root(fa[now])){
if(ch[fa[now]][] == now) r0(now,); else r0(now,);
}else{
int ff = fa[now],gf = fa[ff];
int alpha = ch[gf][]==ff,beta = ch[ff][]==now;
if(alpha^beta) r0(now,beta),r0(now,alpha);
else r0(ff,alpha),r0(now,beta);
}
}
}
void access(int now){
splay(now);ch[now][] = ;push_up(now);
while(fa[now]){
int nxt=fa[now];splay(nxt);ch[nxt][]=now; push_up(nxt); now=nxt;
}
}
void make_root(int now){
access(now);
splay(now);
lazy[now] ^= ;
}
void cut(int u,int v){
make_root(u); access(v); splay(u);
fa[v] = ;
if(ch[u][] == v) ch[u][] = ; else ch[u][] = ;
push_up(u);
}
void link(int u,int v){make_root(u); fa[u] = v;}
int lft(int dt){
splay(dt);
if(lazy[dt]) push_down(dt);
while(ch[dt][]){
dt = ch[dt][];
if(lazy[dt]) push_down(dt);
}
return dt;
}
int find_min(int now){
splay(now);
while(d1[now] != val[now]){
if(val[ch[now][]] == val[now]) now = ch[now][];
else now = ch[now][];
}
return now;
}
}T; int n,m,pre[maxn]; struct edge{int from,to,tmp,len;}edges[maxn]; char str[]; int found(int x){
int rx = x; while(pre[rx] != rx) rx = pre[rx];
while(pre[x]!=rx){int tt = x; pre[x] = rx; x = tt;}
return rx;
} void work(){
T.d1[] = 2e9;T.val[] = 2e9;T.d2[] = ;
for(int i=;i<=n;i++){T.num++;T.d1[i] = 2e9; T.val[i] = 2e9; pre[i] = i;}
for(int i=;i<=m;i++){
scanf("%s",str);
if(str[] == 'f'){
int id;scanf("%d",&id);
scanf("%d%d",&edges[id].from,&edges[id].to);
scanf("%d%d",&edges[id].tmp,&edges[id].len);
edges[id].from++;edges[id].to++;
T.d1[n+id+] = edges[id].tmp; T.d2[n+id+] = edges[id].len;
T.val[n+id+] = edges[id].tmp; T.tot[n+id+] = edges[id].len;
T.make_root(edges[id].from);
T.access(edges[id].to);
int pd = T.lft(edges[id].to);
if(pd == edges[id].from){
if(T.val[edges[id].to] > edges[id].tmp) continue;
int pla = T.find_min(edges[id].to);
T.make_root(pla);T.cut(pla,edges[pla-n-].from);
T.cut(pla,edges[pla-n-].to);
}
T.link(edges[id].from,n+id+);T.link(edges[id].to,n+id+);
pre[found(edges[id].from)] = found(edges[id].to);
}else{
if(str[] == 'm'){
int u,v; scanf("%d%d",&u,&v); v++;u++;
if(found(u) != found(v)){puts("-1");continue;}
T.make_root(u); T.access(v); T.splay(v);
printf("%d\n",T.tot[v]);
}else{
int id,l; scanf("%d%d",&id,&l);
T.make_root(n+id+); T.d2[n+id+] = l;
T.push_up(n+id+);
}
}
}
} int main(){
scanf("%d%d",&n,&m);
work();
return ;
}

UOJ274 [清华集训2016] 温暖会指引我们前行 【LCT】【最大生成树】的更多相关文章

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

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

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

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

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

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

  4. 【bzoj4736/uoj#274】[清华集训2016]温暖会指引我们前行 语文题+LCT

    题目描述 http://uoj.ac/problem/274 题解 语文题+LCT 对于这种语文题建议还是自己读题好一些... 读懂题后发现:由于温度互不相同,最大生成树上的路径必须走(不走的话温度大 ...

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Django Rest framework基础使用之View:APIView, mixins, generic, viewsets

    先看一张图,对DRF的各个APIView,Mixin,Viewset等有个基本印象: 具体使用方法: 1.APIView: DRF 的API视图 有两种实现方式: 一种是基于函数的:@api_view ...

  2. 如何在Github中删除已有仓库或文件

    一.删除已有仓库如果我们想要删除Github中没有用的仓库,应该如何去做呢? 进入到我们需要删除的仓库里面,找到“settings”即仓库设置: 然后,在仓库设置里拉到最底部,找到“Danger Zo ...

  3. duxing201606的原味鸡树

    链接 [http://murphyc.fun/problem/4011] 题意 描述 众所周知,duxing哥非常喜欢原味鸡.众所周知,原味鸡是长在原味鸡树上的. duxing哥因为是水产巨子,所以就 ...

  4. AndroidManifest.xml文件解析

    一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activiti ...

  5. mysql 小数转换成百分数查出(保留两位小数百分数)

    SELECT id as 'ID',GROUP_CONCAT(concat(truncate(royalties *100,2),'%')) as '比例' FROM yser FROM id in( ...

  6. [2017BUAA软工助教]个人项目准备工作

    BUAA软工个人项目准备工作 零.注册Github个人账号(你不会没有吧..) 这是Git的使用教程: http://www.cnblogs.com/schaepher/p/5561193.html ...

  7. Is-a

    在知识表示.面向对象程序设计与面向对象设计的领域里, is-a(英语:subsumption,包含架构)指的是类的父子继承关系, 例如类D是另一个类B的子类(类B是类D的父类). 换句话说,通常&qu ...

  8. WPF中定时器Timer与DispatcherTimer的用法

    最近的工作项目中需要定时更新UI控件中的数据,这时候第一反应肯定会想到去使用System.Timers.Timer定时更新UI控件,但是程序运行后,会发现程序崩溃了.报的异常为“调用线程无法访问此对象 ...

  9. 【Java基础】求出1-100之间偶数和

    结果:

  10. 关于vagrant一个虚拟机搭建多个项目配置(总结)

    问题1:执行vagrant status命令,报错,没有找到命令,翻译:“vargrant bash命令没有找到.” 解答:因为在/home目录中,所有无法执行该命令,需要切换到外部进行执行 问题2: ...