BZOJ.2816.[ZJOI2012]网络(LCT)
对每种颜色维护一个LCT,保存点之间的连接关系。
修改权值A[x]和所有Max[x]都要改;
修改边的颜色先枚举所有颜色,看是否在某种颜色中有边,然后断开。(枚举一遍就行啊 还以为要set什么的存边的颜色)
(条件1直接用数组存233)
修改x的颜色必须先把x旋到根再改!
(好像只能是条链啊)
//3364kb 5952ms
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
const int N=1e4+5;
int n,m,C,q,A[N],num[N][11];
struct LCT
{
#define lson son[x][0]
#define rson son[x][1]
int fa[N],son[N][2],Max[N],sk[N];
bool tag[N];
inline void Update(int x){
Max[x]=std::max(A[x],std::max(Max[lson],Max[rson]));
}
inline bool n_root(int x){
return son[fa[x]][0]==x||son[fa[x]][1]==x;
}
inline void Rev(int x){
std::swap(lson,rson), tag[x]^=1;
}
inline void PushDown(int x){
if(tag[x]) Rev(lson),Rev(rson),tag[x]=0;
}
void Rotate(int x)
{
int a=fa[x],b=fa[a],l=son[a][1]==x,r=l^1;
if(n_root(a)) son[b][son[b][1]==a]=x;
if(son[x][r]) fa[son[x][r]]=a;
fa[a]=x, fa[x]=b, son[a][l]=son[x][r], son[x][r]=a;
Update(a);
}
void Splay(int x)
{
int t=1,a=x; sk[1]=x;
while(n_root(a)) sk[++t]=a=fa[a];
while(t) PushDown(sk[t--]);
while(n_root(x))
{
a=fa[x];
if(n_root(a)) Rotate(son[a][1]==x^son[fa[a]][1]==a?x:a);
Rotate(x);
}
Update(x);
}
void Access(int x){
for(int pre=0; x; x=fa[pre=x])
Splay(x), rson=pre, Update(x);
}
void Make_root(int x){
Access(x), Splay(x), Rev(x);
}
void Split(int x,int y){
Make_root(x), Access(y), Splay(y);
}
int Find_root(int x)
{
Access(x), Splay(x);
while(lson) x=lson;
return x;
}
bool pre_Link(int x,int y){
Make_root(x);
return Find_root(y)!=x;
}
void Link(int x,int y){
fa[x]=y;
}
bool pre_Cut(int x,int y){
Make_root(x);
return Find_root(y)==x&&fa[x]==y&&!rson;
}
void Cut(int x,int y){
fa[x]=son[y][0]=0, Update(y);
}
void Modify(int x,int col){//修改颜色
Access(x), Splay(x), Update(x);
}
}t[10];
inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=gc()) if(c=='-') f=-1;
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now*f;
}
int main()
{
n=read(),m=read(),C=read(),q=read();
for(int i=1; i<=n; ++i) A[i]=read();
for(int u,v,w,i=1; i<=m; ++i)
u=read(),v=read(),w=read(),++num[u][w],++num[v][w],t[w].pre_Link(u,v),t[w].Link(u,v);
int opt,c,x,y,pos;
while(q--)
{
opt=read();
if(!opt){
x=read(),A[x]=y=read();
for(int i=0; i<C; ++i) t[i].Modify(x,y);
}
else if(opt==1){
x=read(),y=read(),c=read(),pos=-1;
for(int i=0; i<C; ++i)
if(t[i].pre_Cut(x,y)) {pos=i; break;}
if(~pos){
if(pos==c) puts("Success.");//这个要判!
else if(num[x][c]>=2||num[y][c]>=2) puts("Error 1.");
else if(!t[c].pre_Link(x,y)) puts("Error 2.");
else t[c].Link(x,y),t[pos].Cut(x,y),--num[x][pos],--num[y][pos],++num[x][c],++num[y][c],puts("Success.");
}
else puts("No such edge.");
}
else{
c=read(),x=read(),y=read();
if(!t[c].pre_Link(x,y)) t[c].Split(x,y), printf("%d\n",t[c].Max[y]);
else puts("-1");
}
}
return 0;
}
BZOJ.2816.[ZJOI2012]网络(LCT)的更多相关文章
- bzoj 2816: [ZJOI2012]网络 (LCT 建多棵树)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2816 题面: http://www.lydsy.com/JudgeOnline/upload ...
- 【刷题】BZOJ 2816 [ZJOI2012]网络
Description http://www.lydsy.com/JudgeOnline/upload/zjoi2012.pdf Solution 维护树上联通块的信息,支持动态加边删边 LCT 总共 ...
- bzoj 2816: [ZJOI2012]网络(splay)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2816 [题意] 给定一个无向图,满足条件:从一个节点出发的同色边不超过2条,且不存在同 ...
- 洛谷 2173 BZOJ 2816 [ZJOI2012]网络
[题解] 明显的LCT模板题,c种颜色就开c棵LCT好了.. #include<cstdio> #include<algorithm> #define N 100010 #de ...
- Luogu 2173 [ZJOI2012]网络 - LCT
Solution $LCT$ 直接上$QuQ$ 注意$cut$ 完 需要 $d[u + c * N]--$ 再 $link$, 不然会输出Error 1的哦 Code #include<cs ...
- ZJOI2012 网络——LCT相关题目
有一个无向图G,每个点有个权值,每条边有一个颜色.这个无向图满足以下两个条件: 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环,同色的环指相同颜色的边构成的环. 在这个图上,你 ...
- BZOJ2816:[ZJOI2012]网络(LCT)
Description 有一个无向图G,每个点有个权值,每条边有一个颜色.这个无向图满足以下两个条件: 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环,同色的环指相同颜色的边构 ...
- luoguP2173 [ZJOI2012]网络 LCT
链接 luogu 思路 颜色很少,开10个lct分别维护 if (Hash.count(make_pair(u, v)) && Hash[make_pair(u, v)] == col ...
- 2816: [ZJOI2012]网络
传送们 把一个点拆成c个即可 浪费时间的水题... //Achen #include<algorithm> #include<iostream> #include<cst ...
随机推荐
- NMS和soft-nms算法
非极大值抑制算法(nms) 1. 算法原理 非极大值抑制算法(Non-maximum suppression, NMS)的本质是搜索局部极大值,抑制非极大值元素. 2. 3邻域情况下NMS的实现 3邻 ...
- Linux input子系统简介
1.前言 本文主要对Linux下的input子系统进行介绍 2. 软件架构 图 input子系统结构图 input子系统主要包括三个部分:设备驱动层.核心层和事件层.我们可以分别理解为:具体的输入设备 ...
- 程序执行的过程分析--【sky原创】
程序执行的过程: 比如我们要执行3 + 2 程序计数器(PC) = 指令地址 指令寄存器(IR) = 正在执行的命令 累加器(AC) = 临时存储体 那么实际上执行了三条指令 每条指令 ...
- SharePoint 2010 使用Install-SPSolution部署wsp包状态一直是”正在部署”
1.服务器场信息如下: 2.使用下面命令部署,状态一直是"正在部署" Install-SPSolution –Identity xxxx.wsp –WebApplication h ...
- 源码编译安装nginx1.4.7
传统上基于进程或线程模型架构的web服务通过每进程或每线程处理并发连接请求,这势必会在网络和I/O操作时产生阻塞,其另一个必然结果则是对内存或CPU的利用率低下.生成一个新的进程/线程需要事先备好其运 ...
- windows下sublime通过sftp扩展上传文件到linux服务器上
首先在package controll下载sftp扩展,在任意磁盘下新建文件夹: 然后,添加该文件夹到sublime中,并在xhell中链接linux服务器,新建目录,mkdir /home/hel ...
- web----粘包
一.什么是粘包 所谓粘包问题主要还是因为接收方不知道消息之间的界限,不知道一次性提取多少字节的数据所造成的. 须知:只有TCP有粘包现象,UDP永远不会粘包 粘包不一定会发生 如果发生了:1.可能是在 ...
- web----Tornado
安装: pip3 install tornado 源码安装 https://pypi.python.org/packages/source/t/tornado/tornado-4.3.tar.gz 简 ...
- python 全栈开发,Day89(sorted面试题,Pycharm配置支持vue语法,Vue基础语法,小清单练习)
一.sorted面试题 面试题: [11, 33, 4, 2, 11, 4, 9, 2] 去重并保持原来的顺序 答案1: list1 = [11, 33, 4, 2, 11, 4, 9, 2] ret ...
- ***使用Fiddler抓取Android安卓手机的APP请求
安装Fiddler,百度搜索Fiddler,就会有下载链接. 启动Fiddler,开始设置.点击“tools-->fiddler options”. 设置HTTPS选项.在设置过程中会有 ...