Solution

由于链信息不好直接维护, 所以新建一个节点存储边的权值, 并把这个节点连向 它所连的节点 $u$, $v$

$pushup$中更新维护的 $mx$ 指向路径上权值最大的边的编号。

由于这题是只有删边, 没有添边, 所以可以离线倒序, 把删边变成添边。

Code

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define rd read()
using namespace std; const int N = 1e6 + ; int n, m, Q, ans[N]; struct edge {
int u, v, id, val, d;
}e[N]; struct que {
int typ, u, v, id;
}q[N]; int read() {
int X = , p = ; char c = getchar();
for (; c > '' || c < ''; c = getchar())
if (c == '-') p = -;
for (; c >= '' && c <= ''; c = getchar())
X = X * + c - '';
return X * p;
} namespace LCT {
int ch[N][], f[N], mx[N], tun[N], val[N];
int st[N], tp;
#define lc(x) ch[x][0]
#define rc(x) ch[x][1] int isroot(int x) {
return rc(f[x]) != x &&
lc(f[x]) != x;
} int get(int x) {
return rc(f[x]) == x;
} void rev(int x) {
swap(lc(x), rc(x));
tun[x] ^= ;
} void pushdown(int x) {
if (tun[x]) {
if (lc(x)) rev(lc(x));
if (rc(x)) rev(rc(x));
tun[x] = ;
}
} void pd(int x) {
while (!isroot(x)) {
st[++tp] = x;
x = f[x];
}
st[++tp] = x;
while (tp) pushdown(st[tp--]);
} void up(int x) {
mx[x] = val[x];
if (e[mx[lc(x)]].val > e[mx[x]].val) mx[x] = mx[lc(x)];
if (e[mx[rc(x)]].val > e[mx[x]].val) mx[x] = mx[rc(x)];
} void rotate(int x) {
int old = f[x], oldf = f[old], son = ch[x][get(x) ^ ];
if (!isroot(old)) ch[oldf][get(old)] = x;
ch[x][get(x) ^ ] = old;
ch[old][get(x)] = son;
f[x] = oldf; f[old] = x; f[son] = old;
up(old); up(x);
} void splay(int x) {
pd(x);
for (; !isroot(x); rotate(x))
if (!isroot(f[x]))
rotate(get(f[x]) == get(x) ? f[x] : x);
} void access(int x) {
for (int y = ; x; y = x, x = f[x])
splay(x), ch[x][] = y, up(x);
} void mroot(int x) {
access(x);
splay(x);
rev(x);
} void split(int x, int y) {
mroot(x);
access(y);
splay(y);
} int findr(int x) {
access(x); splay(x);
while (lc(x)) pushdown(x), x = lc(x);
return x;
} void link(int x, int y) {
mroot(x); f[x] = y;
} void cut(int x, int y) {
split(x, y);
f[x] = ch[y][] = ;
}
}
using namespace LCT; int fd(int x, int y) {
int l = , r = m;
for (; l <= r;) {
int mid = (l + r) >> ;
if (e[mid].u < x || (e[mid].u == x && e[mid].v < y))
l = mid + ;
else if (e[mid].u == x && e[mid].v == y) return mid;
else r = mid - ;
}
return ;
} int cmp1(const edge &A, const edge &B) {
return A.val < B.val;
} int cmp2(const edge &A, const edge &B) {
return A.u == B.u ? A.v < B.v : A.u < B.u;
} int cmp3(const edge &A, const edge &B) {
return A.id < B.id;
} int main()
{
n = rd; m = rd; Q = rd;
for (int i = ; i <= m; ++i) {
e[i].u = rd, e[i].v = rd, e[i].val = rd;
if (e[i].u > e[i].v)
swap(e[i].u, e[i].v);
}
sort(e + , e + + m, cmp1);
for (int i = ; i <= m; ++i)
e[i].id = i, val[i + n] = i;
sort(e + , e + + m, cmp2);
for (int i = ; i <= Q; ++i) {
q[i].typ = rd;
q[i].u = rd;
q[i].v = rd;
if (q[i].u > q[i].v)
swap(q[i].u, q[i].v);
if (q[i].typ == ) {
int t = fd(q[i].u, q[i].v);
q[i].id = e[t].id;
e[t].d = ;
}
}
sort(e + , e + + m, cmp3);
for (int i = , tot = ; i <= m; ++i) if (!e[i].d) {
int x = e[i].u, y = e[i].v;
mroot(x);
if (findr(y) != x) {
link(x, i + n);
link(y, i + n);
tot++;
}
if (tot == n - ) break;
}
for (int i = Q; i; i--) {
if (q[i].typ == ) {
split(q[i].u, q[i].v);
ans[i] = e[mx[q[i].v]].val;
}
else {
int x = q[i].u, y = q[i].v;
mroot(x);
if (findr(y) != x) {
link(y, q[i].id + n);
link(x, q[i].id + n);
continue;
}
if (e[mx[y]].val > e[q[i].id].val) {
int t = mx[y];
cut(t + n, e[t].u);
cut(t + n, e[t].v);
link(q[i].id + n, x);
link(q[i].id + n, y);
}
}
}
for (int i = ; i <= Q; ++i)
if (q[i].typ == )
printf("%d\n", ans[i]);
}

BZOJ 2594 水管局长 - LCT 维护链信息的更多相关文章

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

    失踪人口回归. LCT一直是小C的弱项,特别是这种维护链的信息的,写挂了就会调代码调到心态爆炸. 不过还好这一次的模板练习没有出现太多的意外. Description SC省MY市有着庞大的地下水管网 ...

  2. bzoj 2594: 水管局长数据加强版 Link-Cut-Tree

    题目: Description SC省MY市有着庞大的地下水管网络,嘟嘟是MY市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供水公司可能要将一定量的水从x处送往y处,嘟嘟需要为供水公 ...

  3. BZOJ 2594 水管局长数据加强版

    LCT维护最小生成树 要求两点路径最大的最小,首先想到的肯定是最小生成树,再加上有删边操作,那就得用LCT维护了. 可是对于cut一条边,我们要时刻维护图中的最小生成树,需要把之前被我们淘汰的边找回, ...

  4. Luogu 4234 最小差值生成树 - LCT 维护链信息

    Solution 将边从小到大排序, 添新边$(u, v)$时 若$u,v$不连通则直接添, 若连通则 把链上最小的边去掉 再添边. 若已经加入了 $N - 1$条边则更新答案. Code #incl ...

  5. BZOJ 2594 水管局长数据加强版(动态树)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2594 题意:给出一个无向图,边有权值.定义一条路径的长度为该路径所有边的最大值.两种操作 ...

  6. 洛谷3613睡觉困难综合征(LCT维护链信息(前后缀)+贪心)

    这个题目还是很好啊QWQ很有纪念意义 首先,如果在序列上且是单次询问的话,就是一个非常裸的贪心了QWQ这也是NOI当时原题的问题和数据范围 我们考虑上树的话,应该怎么做? 我的想法是,对于每一位建一个 ...

  7. P4172 [WC2006]水管局长 LCT维护最小生成树

    \(\color{#0066ff}{ 题目描述 }\) SC 省 MY 市有着庞大的地下水管网络,嘟嘟是 MY 市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供水公司可能要将一定量的 ...

  8. luogu P4172 [WC2006]水管局长 LCT维护动态MST + 离线

    Code: #include<bits/stdc++.h> #define maxn 1200000 #define N 120000 using namespace std; char ...

  9. 洛谷.4172.[WC2006]水管局长(LCT Kruskal)

    题目链接 洛谷(COGS上也有) 不想去做加强版了..(其实处理一下矩阵就好了) 题意: 有一张图,求一条x->y的路径,使得路径上最长边尽量短并输出它的长度.会有<=5000次删边. 这 ...

随机推荐

  1. SPSS-因子分析

    因子分析 有可能用较少的综合指标分析存在于各变量中的各类信息,而各综合指标之间彼此是不相关的,代表各类信息的综合指标称为因子.定义:因子分析就是用少数几个因子来描述许多指标或因素之间的联系,以较少几个 ...

  2. 用python来分割图片

    程序思路: 此次程序主要是利用PIL(Python Image Libraty)这库,来进行图片的处理.PIL是一个功能非常强大的python图像处理标准库,但由于PIL只支持python2.7.如今 ...

  3. Appium1.6 定位iOS元素和操作元素

    元素定位方式  第一种:通过Appium1.6的Inspector来查看 具体安装方式前面的随笔已经介绍了:http://www.cnblogs.com/meitian/p/7360017.html ...

  4. Struts2学习资料

    Struts2入门示例教程 http://blog.csdn.net/wwwgeyang777/article/details/19078545     Struts2工作原理 http://blog ...

  5. 最完整Android Studio插件整理 (转)

    转自:http://blog.csdn.net/alpha58/article/details/62881144 现在Android的开发者基本上都使用android Studio进行开发(如果你还在 ...

  6. SpringBoot @Value读取properties文件的属性

    SpringBoot在application.properties文件中,可以自定义属性. 在properties文件中如下示: #自定义属性 mail.fromMail.addr=lgr@163.c ...

  7. cdh 5.13 centos6.9安装

    1.所有节点准备工作 1).关闭防火墙 2).关闭selinux 并重启系统 3).建立NTP服务器,所有数据节点每天定时同步时间. 主节点在ntp.conf中增加 restrict 192.168. ...

  8. Markdown总结整理

    今天朋友(SolskGare)向我普及了一个很方便的文本编辑语言Markdown,才意识到之前自己用鼠标一点一点的排版有多low,而且往往还是费力不讨好.今天我就整理一下Markdown的用法,真的是 ...

  9. [转]github详细教程

    GitHub详解 GitHub 是一个共享虚拟主机服务,用于存放使用Git版本控制的软件代码和内容项目.它由GitHub公司(曾称Logical Awesome)的开发者Chris Wanstrath ...

  10. RxJS之catchError

    Catches errors on the observable to be handled by returning a new observable or throwing an error. 返 ...