【题解】

  明显的LCT模板题,c种颜色就开c棵LCT好了。。

 #include<cstdio>
#include<algorithm>
#define N 100010
#define C 11
#define rg register
#define ls (son[c][u][0])
#define rs (son[c][u][1])
using namespace std;
int n,m,c,k,opt,x,y,w,top;
int cnt[C][N],fa[C][N],son[C][N][],val[N],mx[C][N],rev[C][N],st[N],to[C][N][];
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
inline bool isroot(int c,int u){
return son[c][fa[c][u]][]!=u&&son[c][fa[c][u]][]!=u;
}
inline bool which(int c,int u){
return son[c][fa[c][u]][]==u;
}
inline void pushup(int c,int u){
mx[c][u]=max(max(mx[c][ls],mx[c][rs]),val[u]);
}
inline void pushdown(int c,int u){
rev[c][ls]^=; rev[c][rs]^=; rev[c][u]=; swap(ls,rs);
}
void rotate(int c,int u){
int f=fa[c][u],gf=fa[c][f],wh=which(c,u);
if(!isroot(c,f)) son[c][gf][which(c,f)]=u;
fa[c][u]=fa[c][f]; fa[c][f]=u; fa[c][son[c][u][wh^]]=f;
son[c][f][wh]=son[c][u][wh^]; son[c][u][wh^]=f;
pushup(c,f); pushup(c,u);
}
inline void splay(int c,int u){
st[top=]=u;
for(rg int i=u;!isroot(c,i);i=fa[c][i]) st[++top]=fa[c][i];
for(rg int i=top;i;i--) if(rev[c][st[i]]) pushdown(c,st[i]);
while(!isroot(c,u)){
if(!isroot(c,fa[c][u])) rotate(c,which(c,u)==which(c,fa[c][u])?fa[c][u]:u);
rotate(c,u);
}
}
inline void access(int c,int u){
for(rg int s=;u;s=u,u=fa[c][u]) splay(c,u),son[c][u][]=s,pushup(c,u);
}
inline void makeroot(int c,int u){
access(c,u); splay(c,u); rev[c][u]^=;
}
inline int find(int c,int u){
access(c,u); splay(c,u);
while(ls) u=ls; return u;
}
inline void split(int c,int x,int y){
makeroot(c,x); access(c,y); splay(c,y);
}
inline void link(int c,int x,int y){
cnt[c][x]++; cnt[c][y]++;
if(to[c][x][]==-) to[c][x][]=y; else to[c][x][]=y;
if(to[c][y][]==-) to[c][y][]=x; else to[c][y][]=x;
makeroot(c,x); fa[c][x]=y;
}
inline void cut(int c,int x,int y){
split(c,x,y); int t=son[c][y][];
if(!son[c][t][]&&t==x){
son[c][y][]=,fa[c][x]=,cnt[c][x]--,cnt[c][y]--;
if(to[c][x][]==y) to[c][x][]=-; else to[c][x][]=-;
if(to[c][y][]==x) to[c][y][]=-; else to[c][y][]=-;
}
else{
while(son[c][t][]) t=son[c][t][];
if(t==x){
son[c][fa[c][t]][]=,fa[c][x]=,cnt[c][x]--,cnt[c][y]--;
if(to[c][x][]==y) to[c][x][]=-; else to[c][x][]=-;
if(to[c][y][]==x) to[c][y][]=-; else to[c][y][]=-;
}
}
}
inline bool haveedge(int c,int x,int y){
split(c,x,y); int t=son[c][y][];
if(!son[c][t][]&&t==x) return ;
else{
while(son[c][t][]) t=son[c][t][];
if(t==x) return ;
}
return ;
}
int main(){
n=read(); m=read(); c=read()-; k=read();
for(rg int i=;i<=n;i++){
val[i]=read();
for(rg int j=;j<=c;j++) mx[j][i]=val[i];
}
for(rg int i=;i<=m;i++){
x=read(); y=read(); w=read();
link(w,x,y);
}
while(k--){
if((opt=read())==){
x=read(),y=read();
for(rg int i=;i<=c;i++) access(i,x),splay(i,x);
val[x]=y;
for(rg int i=;i<=c;i++) pushup(i,x);
}
if(opt==){
x=read(),y=read(),w=read(); bool linked=; int lastcol=;
for(rg int i=;i<=c;i++)if(haveedge(i,x,y)){
linked=; lastcol=i; break;
}
// for(rg int i=0;i<=c;i++)if(to[i][x][0]==y||to[i][x][1]==y){
// linked=1; lastcol=i; break;
// }
if(lastcol==w&&linked){
puts("Success."); continue;
}
if(!linked){
puts("No such edge."); continue;
}
if(cnt[w][x]>=||cnt[w][y]>=){
puts("Error 1."); continue;
}
if(find(w,x)==find(w,y)){
puts("Error 2."); continue;
}
cut(lastcol,x,y); link(w,x,y); puts("Success.");
}
if(opt==){
w=read(); x=read(); y=read();
if(find(w,x)!=find(w,y)){
puts("-1"); continue;
}
split(w,x,y); printf("%d\n",mx[w][y]);
}
}
}

洛谷 2173 BZOJ 2816 [ZJOI2012]网络的更多相关文章

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

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

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

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

  3. bzoj 2816: [ZJOI2012]网络(splay)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2816 [题意] 给定一个无向图,满足条件:从一个节点出发的同色边不超过2条,且不存在同 ...

  4. 【刷题】BZOJ 2816 [ZJOI2012]网络

    Description http://www.lydsy.com/JudgeOnline/upload/zjoi2012.pdf Solution 维护树上联通块的信息,支持动态加边删边 LCT 总共 ...

  5. 洛谷 P3307: bzoj 3202: [SDOI2013] 项链

    题目传送门:洛谷P3307.这题在bzoj上是权限题. 题意简述: 这题分为两个部分: ① 有一些珠子,每个珠子可以看成一个无序三元组.三元组要满足三个数都在$1$到$m$之间,并且三个数互质,两个珠 ...

  6. 洛谷 4106 / bzoj 3614 [HEOI2014]逻辑翻译——思路+类似FWT

    题目:https://www.luogu.org/problemnew/show/P4106 https://www.lydsy.com/JudgeOnline/problem.php?id=3614 ...

  7. 洛谷 P3332 BZOJ 3110 [ZJOI2013]K大数查询

    题目链接 洛谷 bzoj 题解 整体二分 Code #include<bits/stdc++.h> #define LL long long #define RG register usi ...

  8. 洛谷 P2486 BZOJ 2243 [SDOI2011]染色

    题目描述 给定一棵有n个节点的无根树和m个操作,操作有2类: 1.将节点a到节点b路径上所有点都染成颜色c: 2.询问节点a到节点b路径上的颜色段数量(连续相同颜色被认为是同一段),如“112221” ...

  9. 洛谷 P2827 BZOJ 4721 UOJ #264 蚯蚓

    题目描述 本题中,我们将用符号表示对c向下取整,例如:. 蛐蛐国最近蚯蚓成灾了!隔壁跳蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手来帮他们消灭蚯蚓. 蛐蛐国里现在共有n只蚯蚓(n为正整数).每只 ...

随机推荐

  1. MySQL权限及登陆、退出方法

    用户权限列表 SELECT 查询权限 INSERT 插入权限 UPDATE 更新权限 DELETE 删除权限(用于删除数据) CREATE 创建权限 DROP 删除权限(用户删除文件) RELOAD ...

  2. Java 8 Stream API的使用示例

    前言 Java Stream API借助于Lambda表达式,为Collection操作提供了一个新的选择.如果使用得当,可以极大地提高编程效率和代码可读性. 本文将介绍Stream API包含的方法 ...

  3. 添加tomcat开机启动服务时报错:Neither the JAVA_HOME nor the JRE_HOME enviromment variable is defined

    首先,参考的 https://blog.csdn.net/wabil/article/details/78818249 的方式添加 tomcat 开机启动,这种方式不需要添加 setenv.sh 文件 ...

  4. [转]Windows Azure平台简介(一):定位与产品结构

    本文转自:http://blog.csdn.net/azurechina/article/details/5592236 http://blogs.msdn.com/b/azchina/archive ...

  5. Git学习笔记(2)-创建仓库

    一.Git简介 1.Git是什么 Git是分布式版本控制系统 2.Git有什么特点 (1)Git是分布式的SCM,SVN是集中式的 (2)Git每个历史版本存储完整的文件,SVN存储文件差异 (3)G ...

  6. Git命令add和commit的区别

    要想弄明白git add和git commit的区别,首先我们需要知道三个概念:工作区(Working Directory).版本库(Repository).暂存区(Stage or index). ...

  7. 《CSS世界》学习笔记(一)

    <CSS世界>,张鑫旭著,人民邮电出版社,2017年12月第一版. 1.P9二维码链接文章的demo值得一看,可以实现有关“某些区域颜色始终保持一致”的效果. P9二维码所链接文章的一个d ...

  8. python数于字符串

    python数于字符串 1.了解数的类型 2.什么事字符串 3.引号的使用与区别 4.转义符 5.自然字符串 6.字符串的重复 7.子字符串 #了解数的类型 1.python中数的类型主要有五种,分为 ...

  9. HTML——meta

    http://www.cnblogs.com/jr1993/p/4542862.html

  10. Shell script之How to write

    Write shell script: 1) Editor like vi or mcedi 2) Set execute permission for your script chmod  perm ...