倒过来就变成了加边
然后就直接LCT

# include <stdio.h>
# include <stdlib.h>
# include <iostream>
# include <algorithm>
# include <string.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll; IL ll Read(){
RG char c = getchar(); RG ll x = 0, z = 1;
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
return x * z;
} const int MAXN(1020000);
int n, m, Q, S[MAXN], ch[2][MAXN], fa[MAXN], mx[MAXN], rev[MAXN];
int w[MAXN], from[MAXN], to[MAXN], id1[MAXN], vis[MAXN];
int qx[MAXN], qy[MAXN], qk[MAXN], ans[MAXN], id2[MAXN], mark[MAXN]; IL bool Son(RG int x){ return ch[1][fa[x]] == x; } IL bool Isroot(RG int x){ return ch[0][fa[x]] != x && ch[1][fa[x]] != x; } IL void Update(RG int x){
mx[x] = x;
if(w[mx[ch[0][x]]] > w[mx[x]]) mx[x] = mx[ch[0][x]];
if(w[mx[ch[1][x]]] > w[mx[x]]) mx[x] = mx[ch[1][x]];
} IL void Pushdown(RG int x){ if(!rev[x]) return; rev[x] = 0; rev[ch[0][x]] ^= 1; rev[ch[1][x]] ^= 1; swap(ch[0][x], ch[1][x]); } IL void Rot(RG int x){
RG int y = fa[x], z = fa[y], c = Son(x);
if(!Isroot(y)) ch[Son(y)][z] = x; fa[x] = z;
ch[c][y] = ch[!c][x]; fa[ch[c][y]] = y;
ch[!c][x] = y; fa[y] = x; Update(y);
} IL void Splay(RG int x){
RG int top = 0; S[++top] = x;
for(RG int y = x; !Isroot(y); y = fa[y]) S[++top] = fa[y];
while(top) Pushdown(S[top--]);
for(RG int y = fa[x]; !Isroot(x); Rot(x), y = fa[x])
if(!Isroot(y)) Son(x) ^ Son(y) ? Rot(x) : Rot(y);
Update(x);
} IL void Access(RG int x){ for(RG int y = 0; x; y = x, x = fa[x]) Splay(x), ch[1][x] = y, Update(x); } IL void Makeroot(RG int x){ Access(x); Splay(x); rev[x] ^= 1; } IL int Findroot(RG int x){ Access(x); Splay(x); while(ch[0][x]) x = ch[0][x]; return x; } IL void Split(RG int x, RG int y){ Makeroot(x); Access(y); Splay(y); } IL void Link(RG int x, RG int y){ Makeroot(x); fa[x] = y; } IL void Cut(RG int x, RG int y){ Split(x, y); fa[x] = ch[0][y] = 0; } IL bool Cmp1(RG int x, RG int y){ return from[x] != from[y] ? from[x] < from[y] : to[x] < to[y]; } IL bool Cmp2(RG int x, RG int y){ return w[x] < w[y]; } IL bool Cmp3(RG int x, RG int y){ return qx[x] != qx[y] ? qx[x] < qx[y] : qy[x] < qy[y]; } int main(RG int argc, RG char* argv[]){
n = Read(); m = Read(); Q = Read();
for(RG int i = 1; i <= m; i++){
from[i] = Read() + m, to[i] = Read() + m, w[i] = Read(), id1[i] = i;
if(from[i] > to[i]) swap(from[i], to[i]);
}
sort(id1 + 1, id1 + m + 1, Cmp1);
for(RG int i = 1; i <= Q; i++){
qk[i] = Read(); qx[i] = Read() + m; qy[i] = Read() + m; id2[i] = i;
if(qx[i] > qy[i]) swap(qx[i], qy[i]);
}
sort(id2 + 1, id2 + Q + 1, Cmp3);
for(RG int i = 1, l = 1; i <= Q && l <= m; i++){
if(qk[id2[i]] == 1) continue;
while(l <= m && (qx[id2[i]] > from[id1[l]] || (qx[id2[i]] == from[id1[l]] && qy[id2[i]] > to[id1[l]]))) l++;
if(l > m) break;
if(qx[id2[i]] == from[id1[l]] && qy[id2[i]] == to[id1[l]]) vis[id1[l]] = 1, mark[id2[i]] = id1[l];
}
sort(id1 + 1, id1 + m + 1, Cmp2);
for(RG int i = 1, t = 0; i <= m; i++){
if(vis[id1[i]]) continue;
if(Findroot(from[id1[i]]) == Findroot(to[id1[i]])) continue;
Link(from[id1[i]], id1[i]); Link(to[id1[i]], id1[i]);
t++; if(t == n - 1) break;
}
for(RG int i = Q; i >= 1; i--){
if(qk[i] == 1) Split(qx[i], qy[i]), ans[i] = w[mx[qy[i]]];
else{
RG int x = from[mark[i]], y = to[mark[i]];
if(Findroot(x) != Findroot(y)) Link(x, mark[i]), Link(y, mark[i]);
else{
Split(x, y);
RG int ma = mx[y], xx = from[ma], yy = to[ma];
if(w[ma] > w[mark[i]]) Cut(xx, ma), Cut(yy, ma), Link(x, mark[i]), Link(y, mark[i]);
}
}
}
for(RG int i = 1; i <= Q; i++)
if(qk[i] == 1) printf("%d\n", ans[i]);
return 0;
}

WC2006水管局长(加强)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. P4172 [WC2006]水管局长

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

  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. Docker安装Nginx1.11.10+php7+MySQL

    Docker安装php-fpm 1.编辑Dockerfile FROM php:7.1.3-fpm ADD sources.list /etc/apt/sources.list RUN cp /usr ...

  2. Python:main函数

    什么是函数? 一个程序可以包含多个模块,程序越复杂,包含的模块和功能就越多,模块细分里面包含多个类,类这个概念在任何一门面向对象语言里面都很重要,在类里面最主要的就是包含的函数,函数式实现某一个功能的 ...

  3. solr6.6教程-从mysql数据库中导入数据(三)

    整理多半天的solr6.6,终于算是把solr6.6中配置数据库弄出来了,网上的文章千篇一律,各说个的,没有一篇统一覆盖solr6.6版本配置的 帖子,本章节我会把配置的一些注意事项一一列举,由于时间 ...

  4. docker容器安装及使用技巧

    关于docker前言 A)首先是关于虚拟化 虚拟化我们可以简单的理解为一种资源管理方式.有如下几种虚拟化的方式: 1.完全虚拟化:对底层硬件实现完全的虚拟.例如:Vmware Workstation ...

  5. linux开放80 端口

    1.使用su登录管理员用户 2.编辑防火墙配置文件 vim /etc/sysconfig/iptables 3.在里面加入后保存 #open port 80 -A INPUT -p TCP -m st ...

  6. 第二十一章 Django的分页与cookie

    第二十一章 Django的分页与cookie 第一课 模板 1.模板的继承 在Template目录下新建模板master.html <!DOCTYPE html> <html lan ...

  7. Flask從入門到入土(三)——模板

    模板是一個包含響應文本的文件,其中包含佔位變量表示的動態部分,其具體值只是請求上下文中才能知道.使用真實值替換變量,再返回最終得到的響應字符串,這一過程稱爲渲染.爲了渲染模板,Flask使用了一個名爲 ...

  8. 2018-03-03-解决win下凭据删除不干净而无法登录共项目录的问题

    layout: post title: 2018-03-03-解决win下凭据删除不干净而无法登录共项目录的问题 key: 20180303 tags: GIT 版本管理 modify_date: 2 ...

  9. 前端时间戳timestamp相关总结:

    一.JavaScript获取当前时间戳的方法 第一种方法:var timestamp = Date.parse(new Date());结果:1280977330000 第二种方法:var times ...

  10. Spark源码编译(未完待续)

    在这里我们不需要搭建独立的Spark集群,利用Yarn Client调用Hadoop集群的计算资源. Spark源码编译生成配置包: 解压源码,在根去根目录下执行以下命令(sbt编译我没尝试) ./m ...