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. RabbitMQ的安装与管理控制台设置

    首先下载安装Erlang环境:http://www.erlang.org/downloads: 再下载安装RabbitMQ:http://www.rabbitmq.com/download.html: ...

  2. 使用jquery如何获取现在时间、并且格式化

    参考网址:https://www.jb51.net/article/94626.html var now=new Date(); $("#total").html(formatTi ...

  3. linux下安装zabbix服务器

    1.lnmp环境安装(linux.nginx.mysql.php) 2.安装php所需模块以及其他模块 yum install -y php-bcmath yum install -y php-mbs ...

  4. jdbc连接模拟用户登陆密码判断

    package com.aaa.demo1; import com.aaa.utils.JdbcUtils; import java.sql.Connection; import java.sql.P ...

  5. js实现简单拖拽效果

    方法如下: var params = { left: 0, top: 0, currentX: 0, currentY: 0, flag: false }; var getCss = function ...

  6. Git 远程仓库 更新url

    git remote -v 查看现有远程仓库的地址url 1. 修改命令git remote set-url origin <URL> 更换远程仓库地址.把<URL>更换为新的 ...

  7. Jenkins安装部署(二)

    Jenkins配置 一.修改jenkins家目录 由于jenkins在启动个之后会默认将所有的构建应用在家目录中创建一遍,为了合理化服务器资源,重新定义jenkins家目录. 在tomcat的cata ...

  8. 【转】自动化测试框架: pytest&allure ,提高自动化健壮性和稳定性

    序 在之前,我写过一个系列“从零开始搭建一个简单的ui自动化测试框架(pytest+selenium+allure)”,在这个系列里,主要介绍了如何从零开始去搭建一个可用的自动化工程框架,但是还缺乏了 ...

  9. MySQL之多表查询练习 与基本查询基础

    MySQL  增删查改 一.增:有2种方法 1.使用insert插入单行数据: 语法:insert [into]<表名> [列名] values <列值> 例:insert i ...

  10. HDU-2054.A==B?(字符串简单处理)

    这道题......被我各种姿势搞死的... 本题大意:给出两个数A和B,判断A和B是否相等,对应输出YES or NO. 本题思路:本题我有两种思路,第一种是直接去除前导零和后导零然后稍加处理比较字符 ...