感觉这题好强啊……本来以为能过,结果毫无疑问的被ge了一顿……在这里记录一下做的过程,也免得以后又忘记啦。

首先,我们应看出在这张图上,要让经过的水管最长的最短,就是要维护一棵动态的最小生成树。只是删除边不是很好操作,所以我们将删边改为加边,反向处理。如果发现新加的边可以更新最小生成树,我们就应该更新图,删去原图中最大的一条边。所以在LCT上我们要多维护一个信息,即当前最大的那条边是哪一条边。至此,大部分的难点都已解决,只是LCT维护的是点上的信息,而这道题的权值都在边上。我们将边转化成点,要将要链接的两个点分别与另一点相连,将信息存在另一个点上即可。

The road is tough and there's still a long way to go. Try your best and don't regret.

#include <bits/stdc++.h>
using namespace std;
#define maxn 150005
#define maxm 1500000
int n, m, opt[maxm], cnp, x[maxm], y[maxm];
int q[maxm], id, T[maxm];
int tot, ans[maxn], mark[maxn];
map <int, int> Map[maxn];
struct node
{
int fa, sum, rev;
int id, v, ch[];
}P[maxm]; struct edge
{
int u, v, t;
friend bool operator <(edge a, edge b)
{
return a.t < b.t;
}
}E[maxn]; int read()
{
int x = , k = ;
char c;
c = getchar();
while(c < '' || c > '') { if(c == '-') k = -; c = getchar(); }
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * k;
} void push_down(int x)
{
if(!P[x].rev) return;
swap(P[x].ch[], P[x].ch[]);
P[P[x].ch[]].rev ^= , P[P[x].ch[]].rev ^= ;
P[x].rev = ;
} void update(int x)
{
if(!x) return;
P[x].id = x, P[x].sum = P[x].v;
if(P[P[x].ch[]].sum > P[x].sum) P[x].sum = P[P[x].ch[]].sum, P[x].id = P[P[x].ch[]].id;
if(P[P[x].ch[]].sum > P[x].sum) P[x].sum = P[P[x].ch[]].sum, P[x].id = P[P[x].ch[]].id;
} bool is_root(int x) { return (P[P[x].fa].ch[] != x) && (P[P[x].fa].ch[] != x); } void rotate(int x)
{
int f = P[x].fa, gf = P[f].fa, k = P[f].ch[] == x;
if(!is_root(f)) P[gf].ch[P[gf].ch[] == f] = x;
P[x].fa = gf, P[f].fa = x;
P[f].ch[k] = P[x].ch[k ^ ], P[P[x].ch[k ^ ]].fa = f;
P[x].ch[k ^ ] = f;
update(f), update(x);
} void Splay(int x)
{
int top = ; q[top] = x;
for(int i = x; !is_root(i); i = P[i].fa) q[++ top] = P[i].fa;
for(int i = top; i; i --) push_down(q[i]);
while(!is_root(x))
{
int f = P[x].fa, gf = P[f].fa;
if(!is_root(f)) (P[f].ch[] == x) ^ (P[gf].ch[] == f) ? rotate(x) : rotate(f);
rotate(x);
}
update(x);
} void Access(int x)
{
for(int ff = ; x; ff = x, x = P[x].fa)
{
Splay(x);
P[x].ch[] = ff;
update(x);
}
} void make_root(int x) { Access(x); Splay(x); P[x].rev ^= ; }
void Split(int u, int v) { make_root(u); Access(v); Splay(v); }
void Link(int u, int v) { make_root(u); P[u].fa = v; }
void Cut(int u, int v) { Split(u, v); P[v].ch[] = P[u].fa = ; } int Get_fa(int x)
{
Access(x); Splay(x);
while(P[x].ch[]) x = P[x].ch[];
return x;
} int main()
{
n = read(), m = read();
int q = read();
for(int i = ; i <= m; i ++)
{
int u = read(), v = read(), w = read(); T[i] = w;
E[++ cnp].u = u; E[cnp].v = v, E[cnp].t = w;
}
sort(E + , E + + m);
for(int i = ; i <= m; i ++) Map[E[i].u][E[i].v] = Map[E[i].v][E[i].u] = i;
for(int i = ; i <= q; i ++)
{
opt[i] = read(); x[i] = read(); y[i] = read();
if(opt[i] == ) mark[Map[x[i]][y[i]]] = ;
}
for(int i = ; i <= m; i ++)
{
int u = E[i].u, v = E[i].v, t = E[i].t;
if(!mark[Map[u][v]] && Get_fa(u) != Get_fa(v))
{
id = i + n, P[id].sum = P[id].v = t;
Link(u, id), Link(id, v);
}
}
for(int i = q; i; i --)
{
Split(x[i], y[i]);
if(opt[i] == ) // find a route
ans[++ tot] = P[y[i]].sum;
else // add edge
{
int now = n + Map[x[i]][y[i]];
int tem = E[now - n].t;
if(tem < P[y[i]].sum)
{
P[now].v = tem; tem = P[y[i]].id;
Cut(tem, E[tem - n].u); Cut(tem, E[tem - n].v);
Link(now, x[i]), Link(now, y[i]);
}
}
}
for(int i = tot; i; i --)
printf("%d\n", ans[i]);
return ;
}

【题解】[WC2006]水管局长的更多相关文章

  1. BZOJ2594: [Wc2006]水管局长数据加强版

    题解: 裸LCT+离线+二分+MST... 代码:(几乎摘抄自hzwer) #include<cstdio> #include<cstdlib> #include<cma ...

  2. P4172 [WC2006]水管局长

    P4172 [WC2006]水管局长 前言 luogu数据太小 去bzoj,他的数据大一些 思路 正着删不好维护 那就倒着加,没了 LCT维护他的最小生成树MST 树上加一条边肯定会有一个环 看看环上 ...

  3. bzoj 2594: [Wc2006]水管局长数据加强版 动态树

    2594: [Wc2006]水管局长数据加强版 Time Limit: 25 Sec  Memory Limit: 128 MBSubmit: 934  Solved: 291[Submit][Sta ...

  4. BZOJ 2594: [Wc2006]水管局长数据加强版( LCT )

    离线然后就是维护加边的动态MST, Link cut tree秒掉..不过我写+调了好久...时间复杂度O(NlogN + MlogM) ------------------------------- ...

  5. [bzoj2594][Wc2006]水管局长数据加强版 (lct)

    论蒟蒻的自我修养T_T.. 和noi2014魔法森林基本一样...然而数据范围大得sxbk...UPD:这题如果用lct判联通的话可能会被卡到O(mlogm)..所以最好还是用并查集吧 一开始数组开太 ...

  6. BZOJ 2594: [Wc2006]水管局长数据加强版 [LCT kruskal]

    2594: [Wc2006]水管局长数据加强版 Time Limit: 25 Sec  Memory Limit: 128 MBSubmit: 2917  Solved: 918[Submit][St ...

  7. BZOJ_2594_[Wc2006]水管局长数据加强版_LCT

    BZOJ_2594_[Wc2006]水管局长数据加强版_LCT Description SC省MY市有着庞大的地下水管网络,嘟嘟是MY市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供 ...

  8. P4172 [WC2006]水管局长(LCT)

    P4172 [WC2006]水管局长 LCT维护最小生成树,边权化点权.类似 P2387 [NOI2014]魔法森林(LCT) 离线存储询问,倒序处理,删边改加边. #include<iostr ...

  9. [BZOJ2594][WC2006]水管局长加强版(LCT+Kruskal)

    2594: [Wc2006]水管局长数据加强版 Time Limit: 25 Sec  Memory Limit: 128 MBSubmit: 4452  Solved: 1385[Submit][S ...

  10. [BZOJ2594] [WC2006]水管局长(Kruskal+LCT)

    [BZOJ2594] [WC2006]水管局长(Kruskal+LCT) 题面 SC省MY市有着庞大的地下水管网络,嘟嘟是MY市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供水公司可 ...

随机推荐

  1. MySQL Waiting for table metadata lock的解决方法

    最近需要在某一个表中新增字段,使用Sequel Pro 或者Navicat工具都会出现程序没有反应,使用 show processlist 查看,满屏都是 Waiting for table meta ...

  2. Layabox进阶之资源加载

    资源加载失败,图片资源默认类型是image 如果是sprite可能找不到. 资源的加载顺序,场景被加载出来时,要判断该场景的资源是否都已经加载到. 点击A界面弹出来B界面,A界面的资源要在B界面之前加 ...

  3. React学习(2)—— 组件的运用和数据传递

    React官方中文文档地址:    https://doc.react-china.org/ 了解了组件之后,就需要理解“Props”和“State”的用法.首先来介绍State,State按照字面意 ...

  4. less学习一

    Less 是一门 CSS 预处理语言,它扩展了 CSS 语言,增加了变量.Mixin.函数等特性,使 CSS 更易维护和扩展. Less 可以运行在 Node 或浏览器端. less文件只有被编译后才 ...

  5. asp.net core mvc简介

    MVC 通常而言,我们使用.NET Core MVC 构建网页应用与 API,MVC是使用模型-视图-控制器(Model-View-Controller)设计模式. 创建项目 使用如下命令创建一个名称 ...

  6. 牛客暑假多校第六场I-Team Rocket

    一.题意 我们是穿越银河的火箭队....... 给出若干个区间,之后给出若干个点,要求对每个点求出,第一个覆盖点的区间的数量,之后用当前所有点覆盖的区间的序号的乘积结合输入的Y来生成下一位点.最后输出 ...

  7. MOVE-PERCENTAGE(文字列の部分の代入)

    以下の MOVE 命令のバリアントは.c 型項目についてのみ機能します. MOVE c1 TO c2 PERCENTAGE p [RIGHT]. 左寄せした (RIGHT オプションを指定した場合は右 ...

  8. dubbo-admin管理控制台安装和使用

    现在链接都变成了https://github.com/apache/incubator-dubbo/,找不到dubbo-admin这个目录. 那就直接去下载他们打包好的源代码:https://gith ...

  9. c++返回引用

    #include <iostream> #include <ctime> using namespace std; double vals[] = {10.1, 12.6, 3 ...

  10. Selenium驱动Chrome浏览器

    import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome ...