【题解】

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

  1. #include<cstdio>
  2. #include<algorithm>
  3. #define N 100010
  4. #define C 11
  5. #define rg register
  6. #define ls (son[c][u][0])
  7. #define rs (son[c][u][1])
  8. using namespace std;
  9. int n,m,c,k,opt,x,y,w,top;
  10. int cnt[C][N],fa[C][N],son[C][N][],val[N],mx[C][N],rev[C][N],st[N],to[C][N][];
  11. inline int read(){
  12. int k=,f=; char c=getchar();
  13. while(c<''||c>'')c=='-'&&(f=-),c=getchar();
  14. while(''<=c&&c<='')k=k*+c-'',c=getchar();
  15. return k*f;
  16. }
  17. inline bool isroot(int c,int u){
  18. return son[c][fa[c][u]][]!=u&&son[c][fa[c][u]][]!=u;
  19. }
  20. inline bool which(int c,int u){
  21. return son[c][fa[c][u]][]==u;
  22. }
  23. inline void pushup(int c,int u){
  24. mx[c][u]=max(max(mx[c][ls],mx[c][rs]),val[u]);
  25. }
  26. inline void pushdown(int c,int u){
  27. rev[c][ls]^=; rev[c][rs]^=; rev[c][u]=; swap(ls,rs);
  28. }
  29. void rotate(int c,int u){
  30. int f=fa[c][u],gf=fa[c][f],wh=which(c,u);
  31. if(!isroot(c,f)) son[c][gf][which(c,f)]=u;
  32. fa[c][u]=fa[c][f]; fa[c][f]=u; fa[c][son[c][u][wh^]]=f;
  33. son[c][f][wh]=son[c][u][wh^]; son[c][u][wh^]=f;
  34. pushup(c,f); pushup(c,u);
  35. }
  36. inline void splay(int c,int u){
  37. st[top=]=u;
  38. for(rg int i=u;!isroot(c,i);i=fa[c][i]) st[++top]=fa[c][i];
  39. for(rg int i=top;i;i--) if(rev[c][st[i]]) pushdown(c,st[i]);
  40. while(!isroot(c,u)){
  41. if(!isroot(c,fa[c][u])) rotate(c,which(c,u)==which(c,fa[c][u])?fa[c][u]:u);
  42. rotate(c,u);
  43. }
  44. }
  45. inline void access(int c,int u){
  46. for(rg int s=;u;s=u,u=fa[c][u]) splay(c,u),son[c][u][]=s,pushup(c,u);
  47. }
  48. inline void makeroot(int c,int u){
  49. access(c,u); splay(c,u); rev[c][u]^=;
  50. }
  51. inline int find(int c,int u){
  52. access(c,u); splay(c,u);
  53. while(ls) u=ls; return u;
  54. }
  55. inline void split(int c,int x,int y){
  56. makeroot(c,x); access(c,y); splay(c,y);
  57. }
  58. inline void link(int c,int x,int y){
  59. cnt[c][x]++; cnt[c][y]++;
  60. if(to[c][x][]==-) to[c][x][]=y; else to[c][x][]=y;
  61. if(to[c][y][]==-) to[c][y][]=x; else to[c][y][]=x;
  62. makeroot(c,x); fa[c][x]=y;
  63. }
  64. inline void cut(int c,int x,int y){
  65. split(c,x,y); int t=son[c][y][];
  66. if(!son[c][t][]&&t==x){
  67. son[c][y][]=,fa[c][x]=,cnt[c][x]--,cnt[c][y]--;
  68. if(to[c][x][]==y) to[c][x][]=-; else to[c][x][]=-;
  69. if(to[c][y][]==x) to[c][y][]=-; else to[c][y][]=-;
  70. }
  71. else{
  72. while(son[c][t][]) t=son[c][t][];
  73. if(t==x){
  74. son[c][fa[c][t]][]=,fa[c][x]=,cnt[c][x]--,cnt[c][y]--;
  75. if(to[c][x][]==y) to[c][x][]=-; else to[c][x][]=-;
  76. if(to[c][y][]==x) to[c][y][]=-; else to[c][y][]=-;
  77. }
  78. }
  79. }
  80. inline bool haveedge(int c,int x,int y){
  81. split(c,x,y); int t=son[c][y][];
  82. if(!son[c][t][]&&t==x) return ;
  83. else{
  84. while(son[c][t][]) t=son[c][t][];
  85. if(t==x) return ;
  86. }
  87. return ;
  88. }
  89. int main(){
  90. n=read(); m=read(); c=read()-; k=read();
  91. for(rg int i=;i<=n;i++){
  92. val[i]=read();
  93. for(rg int j=;j<=c;j++) mx[j][i]=val[i];
  94. }
  95. for(rg int i=;i<=m;i++){
  96. x=read(); y=read(); w=read();
  97. link(w,x,y);
  98. }
  99. while(k--){
  100. if((opt=read())==){
  101. x=read(),y=read();
  102. for(rg int i=;i<=c;i++) access(i,x),splay(i,x);
  103. val[x]=y;
  104. for(rg int i=;i<=c;i++) pushup(i,x);
  105. }
  106. if(opt==){
  107. x=read(),y=read(),w=read(); bool linked=; int lastcol=;
  108. for(rg int i=;i<=c;i++)if(haveedge(i,x,y)){
  109. linked=; lastcol=i; break;
  110. }
  111. // for(rg int i=0;i<=c;i++)if(to[i][x][0]==y||to[i][x][1]==y){
  112. // linked=1; lastcol=i; break;
  113. // }
  114. if(lastcol==w&&linked){
  115. puts("Success."); continue;
  116. }
  117. if(!linked){
  118. puts("No such edge."); continue;
  119. }
  120. if(cnt[w][x]>=||cnt[w][y]>=){
  121. puts("Error 1."); continue;
  122. }
  123. if(find(w,x)==find(w,y)){
  124. puts("Error 2."); continue;
  125. }
  126. cut(lastcol,x,y); link(w,x,y); puts("Success.");
  127. }
  128. if(opt==){
  129. w=read(); x=read(); y=read();
  130. if(find(w,x)!=find(w,y)){
  131. puts("-1"); continue;
  132. }
  133. split(w,x,y); printf("%d\n",mx[w][y]);
  134. }
  135. }
  136. }

洛谷 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. bzoj 1574: [Usaco2009 Jan]地震损坏Damage【dfs】

    和March的那道不一样,只是非常单纯的带着贪心的dfs 首先一个点被隔断,与它相邻的所有点也会被隔断,打上删除标记,从1dfs即可 #include<iostream> #include ...

  2. bzoj1528 sam-Toy Cars(贪心,优先队列)

    「BZOJ1528」[POI2005] sam – Toy Cars Description Jasio 是一个三岁的小男孩,他最喜欢玩玩具了,他有n 个不同的玩具,它们都被放在了很高的架子上所以Ja ...

  3. web界面bug-临时

    一.登录页面 二.首页 三.项目 四.项目池 五.专家管理 六.审批 七.日/周报 八.设置

  4. 实数类型c++

    数据类型 定义标识符 数值范围 占字节数 有效位数 单精度浮点数 float -3.4E+38-3.4E+38 4(32位) 6-7位 双精度浮点数 double -1.7E+308-1.7E+308 ...

  5. EditText(4)常用属性详解

    常用的属性: 显示密码 通过设置EditText的setTransformationMethod()方法来实现隐藏密码或这显示密码. editText.setTransformationMethod( ...

  6. Visual C++ Windows 桌面应用程序样例(摘抄)

    //================================== //Windows应用程序框架结构(例子) //参考:<Visual C++宝典>陈国建等编著 //======= ...

  7. [转]MySQL存储过程

    转自:http://www.cnblogs.com/exmyth/p/3303470.html 14.1.1 创建存储过程 MySQL中,创建存储过程的基本形式如下: CREATE PROCEDURE ...

  8. 继承static的注意点

    继承static的注意点 singleton模式会使用 <?php class Auth { protected static $_instance = null; /** * 单用例入口 * ...

  9. 冒泡 [Python]

    冒泡Python class BubbleSort: def __init__(self): self.initArr() def initArr(self): self.arrInfo = [60, ...

  10. C++(extern关键字的理解和作用深入)

    extern关键字的理解和作用深入 extern是一个关键字,它告诉编译器存在着一个变量或者一个函数,如果在当前编译语句的前面中没有找到相应的变量或者函数, 也会在当前文件的后面或者其它文件中定义 引 ...