题目分析:

差评,最大生成树裸题。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. 【IE11请求中止】 XMLHttpRequest: 网络错误 0x2ef3的意外出现

    BUG现象 今天排查BUG遇到一个有趣的BUG,测试的截图显示 这个BUG只在IE11下出现. BUG原因 这个问题的原因是keep-alive机制引起. 当浏览器在向一个网址发起请求时,会建立一个t ...

  2. 我去年码了个表(WPF MvvM)

    又快个把月没写博客了(最近忙着学JAVA去了,都是被逼的/(ㄒoㄒ)/~~),然后用WPF码了个表,其实想加上那种提醒功能什么的,额,就这样了吧,主要是感受一下数据驱动的思想. 效果如下: 前端XAM ...

  3. getQueryStringByName url参数/

    MasterId: (masterIdUrl != null && masterIdUrl != "") ? masterIdUrl : null ClassId: ...

  4. Servlet 使用ServletContext共享数据,读取web.xml配置

    ServletContext对象 session和cookie,对于每一个请求用户来说,都是不同的,因为要保证隐私安全. 而有一些数据,可以让所有用户共享,此时就可以用ServletContext对象 ...

  5. 安全测试学习之bWAPP环境搭建

    安装环境:window7+IIS+mysql+php bWAPP下载地址:https://sourceforge.net/projects/bwapp/files/bee-box/  ,直接点击Dow ...

  6. C#复习笔记(4)--C#3:革新写代码的方式(Lambda表达式和表达式树)

    Lambda表达式和表达式树 先放一张委托转换的进化图 看一看到lambda简化了委托的使用. lambda可以隐式的转换成委托或者表达式树.转换成委托的话如下面的代码: Func<string ...

  7. 网络编程--使用TCP协议发送接收数据

    package com.zhangxueliang.tcp; import java.io.IOException; import java.io.OutputStream; import java. ...

  8. git fetch 和git pull 的差别

    1.git fetch 相当于是从远程获取最新到本地,不会自动merge,如下指令: git fetch orgin master //将远程仓库的master分支下载到本地当前branch中 git ...

  9. css特殊样式

    span{ color: blue; border:1px solid black;}.extra span{ color: inherit;} 清除原有样式 text-decoration: non ...

  10. MQ4入门篇(一)

    写一个下单功能,和一个平仓功能: 下单: 1:下单使用到的函 int OrderSend(string symbol, int cmd, double volume, double price, in ...