题目链接

  这次坑我的是与或的结合顺序……

  开十个LCT记录一下即可。以上。

  

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cctype>
#include<map>
#define maxn 210050
#define maxc 12
using namespace std;
inline long long read(){
long long num=,f=;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') f=-;
ch=getchar();
}
while(isdigit(ch)){
num=num*+ch-'';
ch=getchar();
}
return num*f;
} struct Splay{
struct Node{
int e[],fa,val,maxi,tag;
}tree[maxn];
inline int iden(int x){ return x==tree[tree[x].fa].e[]; }
inline void connect(int x,int fa,int how){ tree[x].fa=fa; tree[fa].e[how]=x; }
inline bool isroot(int x){ return x!=tree[tree[x].fa].e[]&&x!=tree[tree[x].fa].e[]; }
inline void update(int x){ tree[x].maxi=max(tree[x].val,max(tree[tree[x].e[]].maxi,tree[tree[x].e[]].maxi)); }
void reverse(int x){
swap(tree[x].e[],tree[x].e[]);
tree[x].tag^=;
}
void pushdown(int x){
if(tree[x].tag==) return;
tree[x].tag=;
if(tree[x].e[]) reverse(tree[x].e[]);
if(tree[x].e[]) reverse(tree[x].e[]);
}
void rotate(int x){
int y=tree[x].fa; int r=tree[y].fa;
int sony=iden(x); int sonr=iden(y);
tree[x].fa=r; if(!isroot(y)) tree[r].e[sonr]=x;
int b=tree[x].e[sony^];
connect(b,y,sony);
connect(y,x,sony^);
update(y);
}
inline void pushto(int x){
if(!isroot(x)) pushto(tree[x].fa);
pushdown(x);
return;
}
void splay(int x){
pushto(x);
while(!isroot(x)){
int fa=tree[x].fa;
if(!isroot(fa))
if(iden(fa)==iden(x)) rotate(fa);
else rotate(x);
rotate(x);
}
update(x);
}
inline void access(int x){
int last=;
while(x){
splay(x);
tree[x].e[]=last;
update(x);
last=x; x=tree[x].fa;
}
}
inline void makeroot(int x){
access(x);
splay(x);
reverse(x);
}
inline int findroot(int x){
access(x);
splay(x);
while(tree[x].e[]) x=tree[x].e[];
return x;
}
inline void split(int x,int y){
makeroot(x);
access(y);
splay(y);
}
inline void link(int x,int y){
split(x,y);
tree[x].fa=y;
}
inline void cut(int x,int y){
split(x,y);
if(tree[y].e[]!=x||tree[x].e[]) return;
tree[x].fa=tree[y].e[]=;
}
}s[maxc]; inline long long calc(long long x,long long y,long long n){ return x*n+y; }
map<long long,int>d; int old[maxn];
int sum[maxn][maxc]; int main(){
int n=read(),m=read(),c=read(),e=read();
for(int i=;i<=n;++i){
int x=read();
for(int j=;j<=c;++j) s[j].tree[i].val=s[j].tree[i].maxi=x;
}
for(int i=;i<=m;++i){
int from=read(),to=read(),col=read();
sum[from][col]++; sum[to][col]++;
old[i+n]=col;
if(from>to) swap(from,to);
d[calc(from,to,n)]=i+n;
s[col].link(from,i+n);
s[col].link(to,i+n);
}
for(int i=;i<=e;++i){
int opt=read();
if(opt==){
int x=read(),y=read();
for(int j=;j<=c;++j){
s[j].splay(x);
s[j].tree[x].val=y;
s[j].update(x);
}
}
else if(opt==){
int from=read(),to=read(),col=read();
if(from>to) swap(from,to);
if(d.count(calc(from,to,n))==){
printf("No such edge.\n");
continue;
}
int id=d[calc(from,to,n)];
if(col==old[id]){
printf("Success.\n");
continue;
}
if(sum[from][col]==||sum[to][col]==){
printf("Error 1.\n");
continue;
}
if(s[col].findroot(from)==s[col].findroot(to)){
printf("Error 2.\n");
continue;
}
sum[from][old[id]]--; sum[to][old[id]]--;
sum[from][col]++; sum[to][col]++;
s[old[id]].cut(from,id);
s[old[id]].cut(to,id);
old[id]=col;
s[old[id]].link(from,id);
s[old[id]].link(to,id);
printf("Success.\n");
}
else{
int col=read(),x=read(),y=read();
if(s[col].findroot(x)!=s[col].findroot(y)){
printf("-1\n");
continue;
}
s[col].split(x,y);
//printf("%d %d>>>\n",y,s[col].tree[y].val);
printf("%d\n",s[col].tree[y].maxi);
}
}
return ;
}

【Luogu】P2173网络(LCT)的更多相关文章

  1. Luogu 2173 [ZJOI2012]网络 - LCT

    Solution $LCT$ 直接上$QuQ$ 注意$cut$ 完 需要 $d[u + c * N]--$ 再  $link$,  不然会输出Error 1的哦 Code #include<cs ...

  2. Luogu P2173 [ZJOI2012]网络

    题意 写的比较清楚,我就不解释了. \(\texttt{Data Range:}n\leq 10^4,m\leq 10^5,c\leq 10,k\leq 10^5\) 题解 注意到 \(c\) 的范围 ...

  3. ZJOI2012 网络——LCT相关题目

    有一个无向图G,每个点有个权值,每条边有一个颜色.这个无向图满足以下两个条件: 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环,同色的环指相同颜色的边构成的环. 在这个图上,你 ...

  4. luoguP2173 [ZJOI2012]网络 LCT

    链接 luogu 思路 颜色很少,开10个lct分别维护 if (Hash.count(make_pair(u, v)) && Hash[make_pair(u, v)] == col ...

  5. bzoj 2816: [ZJOI2012]网络 (LCT 建多棵树)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2816 题面: http://www.lydsy.com/JudgeOnline/upload ...

  6. BZOJ.2816.[ZJOI2012]网络(LCT)

    题目链接 BZOJ 洛谷 对每种颜色维护一个LCT,保存点之间的连接关系. 修改权值A[x]和所有Max[x]都要改: 修改边的颜色先枚举所有颜色,看是否在某种颜色中有边,然后断开.(枚举一遍就行啊 ...

  7. BZOJ2816:[ZJOI2012]网络(LCT)

    Description 有一个无向图G,每个点有个权值,每条边有一个颜色.这个无向图满足以下两个条件: 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环,同色的环指相同颜色的边构 ...

  8. 【luogu P3376 网络最大流】 模板

    题目链接:https://www.luogu.org/problemnew/show/P3376 #include <iostream> #include <cstdio> # ...

  9. Luogu P4299 首都 LCT

    既然是中文题目,这里便不给题意. 分析: 这个题的做法据说是启发式合并? 但是我不会啊…… 进入正题,LCT是怎样做掉这道题的.记得在前面的一篇<大融合>的题解中,介绍过LCT维护子树信息 ...

随机推荐

  1. Java 集合框架_上

    集合框架被设计成要满足以下几个目标. 该框架必须是高性能的.基本集合(动态数组,链表,树,哈希表)的实现也必须是高效的. 该框架允许不同类型的集合,以类似的方式工作,具有高度的互操作性. 对一个集合的 ...

  2. datetime 插件

    1  写一段文本 <div id="nomarl-wrap"> <div class="form-group"> <label c ...

  3. H1ctf-Vote

    用来练习IO_FILE利用 glibc-2.23 # coding:utf-8 from pwn import * from FILE import * context.arch = 'amd64' ...

  4. CUDA高性能编程中文实战11章例子中多设备的例子编译提示问题

    提示的问题如下: error : argument of type "void *(*)(void *)" is incompatible with parameter of ty ...

  5. 小波变换(wavelet transform)的通俗解释(一)

    小波变换 小波,一个神奇的波,可长可短可胖可瘦(伸缩平移),当去学习小波的时候,第一个首先要做的就是回顾傅立叶变换(又回来了,唉),因为他们都是频率变换的方法,而傅立叶变换是最入门的,也是最先了解的, ...

  6. 短短几行css代码实现滚动条效果

    如何实现使用css实现滚动条效果 实现效果,运用线性渐变来实现功能 假设我们的页面被包裹在 <body> 中,可以滚动的是整个 body,给它添加这样一个从左下到到右上角的线性渐变: bo ...

  7. mysql 查询 7天内的数据

    SELECT ID,SERVICE FROM new_schedules_spider_full WHERE SERVICE = 'WSA2' and date_sub(curdate(), inte ...

  8. 十、MySQL 删除数据表

    MySQL 删除数据表 MySQL中删除数据表是非常容易操作的, 但是你再进行删除表操作时要非常小心,因为执行删除命令后所有数据都会消失. 语法 以下为删除MySQL数据表的通用语法: DROP TA ...

  9. JavaScript日期加减

    JS中的日期加减使用以下方式: varcurrentDate = new Date(); 对日期加减: date.setDate(date.getDate()+n); 对月加减: date.setMo ...

  10. SpringBoot AOP综合例子

    完整源码:https://github.com/947133297/cgLibDemo 通过AOP来便捷地输出日志,能更加方便排查系统的bug,这个例子中简单输出自定义文件和函数执行时的参数,函数要不 ...