Solution

$LCT$ 直接上$QuQ$

注意$cut$ 完 需要 $d[u + c * N]--$ 再  $link$,  不然会输出Error 1的哦

Code

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define rd read()
using namespace std; const int N = 1e5 + ; int n, m, col, Q; int read() {
int X = , p = ; char c = getchar();
for (; c > '' || c < ''; c = getchar())
if (c == '-' ) p = -;
for (; c >= '' && c <= ''; c = getchar())
X = X * + c - '';
return X * p;
} void cmax(int &a, int b) {
if (a < b)
a = b;
} namespace LCT {
int val[N], Max[N], f[N], ch[N][], tun[N], d[N];
#define lc(x) ch[x][0]
#define rc(x) ch[x][1]
int isroot(int x) {
return rc(f[x]) != x && lc(f[x]) != x;
} int get(int x) {
return rc(f[x]) == x;
} void up(int x) {
Max[x] = val[x];
if (lc(x)) cmax(Max[x], Max[lc(x)]);
if (rc(x)) cmax(Max[x], Max[rc(x)]);
} void rev(int x) {
swap(lc(x), rc(x));
tun[x] ^= ;
} void pushdown(int x) {
if (tun[x]) {
if (lc(x)) rev(lc(x));
if (rc(x)) rev(rc(x));
tun[x] = ;
}
} void pd(int x) {
if (!isroot(x))
pd(f[x]);
pushdown(x);
} void rotate(int x) {
int old = f[x], oldf = f[old], son = ch[x][get(x) ^ ];
if (!isroot(old)) ch[oldf][get(old)] = x;
ch[x][get(x) ^ ] = old;
ch[old][get(x)] = son;
f[old] = x; f[son] = old; f[x] = oldf;
up(old); up(x);
} void splay(int x) {
pd(x);
for (; !isroot(x); rotate(x))
if (!isroot(f[x]))
rotate(get(f[x]) == get(x) ? f[x] : x);
} void access(int x) {
for (int y = ; x; y = x, x = f[x])
splay(x), ch[x][] = y, up(x);
} void mroot(int x) {
access(x); splay(x); rev(x);
} int findr(int x) {
access(x); splay(x);
while (lc(x)) pushdown(x), x = lc(x);
return x;
} void split(int x, int y) {
mroot(x); access(y); splay(y);
} int link(int x, int y) {
if (d[x] > || d[y] > )
return ;
mroot(x);
if (findr(y) == x)
return ;
f[x] = y;
return ;
} int cut(int x, int y) {
mroot(x);
if (findr(y) != x || f[x] != y || ch[x][])
return ;
f[x] = ch[y][] = ;
return ;
}
}
using namespace LCT; int main()
{
n = rd; m = rd; col = rd; Q = rd;
for (int i = ; i <= n; ++i) {
int tmp = rd;
for (int j = ; j < col; ++j)
val[i + j * n] = tmp;
}
for (int i = ; i <= m; ++i) {
int u = rd, v = rd, z = rd;
link(u + z * n, v + z * n);
d[u + z * n]++;
d[v + z * n]++;
}
for (; Q; Q--) {
int k = rd;
if (k == ) {
int u = rd, v = rd;
for (int j = ; j < col; ++j)
mroot(u + j * n), val[u + j * n] = v, up(u + j * n);
}
if (k == ) {
int u = rd, v = rd, z = rd, flag = , c;
for (int j = ; j < col && !flag; ++j) {
flag = cut(u + j * n, v + j * n);
if (flag) c = j;
}
if (!flag) {puts("No such edge."); continue;}
d[u + c * n]--; d[v + c * n]--;
flag = link(u + z * n, v + z * n);
if (flag == ) {
puts("Error 1.");
link(u + c * n, v + c * n);
d[u + c * n]++; d[v + c * n]++;
}
else if (flag == ) {
puts("Error 2.");
link(u + c * n, v + c * n);
d[u + c * n]++; d[v + c * n]++;
}
else {
puts("Success.");
d[u + z * n]++; d[v + z * n]++;
}
}
if (k == ) {
int z = rd, u = rd, v = rd;
u = u + z * n;
v = v + z * n;
mroot(u);
if (findr(v) != u) {puts("-1"); continue;}
printf("%d\n", max(Max[lc(v)], val[v]));
}
}
}

Luogu 2173 [ZJOI2012]网络 - LCT的更多相关文章

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

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

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

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

  3. luoguP2173 [ZJOI2012]网络 LCT

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

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

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

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

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

  6. Luogu P2173 [ZJOI2012]网络

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

  7. 洛谷 P2173 [ZJOI2012]网络 解题报告

    P2173 [ZJOI2012]网络 题目描述 有一个无向图G,每个点有个权值,每条边有一个颜色.这个无向图满足以下两个条件: 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环, ...

  8. [Luogu 2604] ZJOI2010 网络扩容

    [Luogu 2604] ZJOI2010 网络扩容 第一问直接最大流. 第二问,添加一遍带费用的边,边权 INF,超级源点连源点一条容量为 \(k\) 的边来限流,跑费用流. 大约是第一次用 nam ...

  9. ZJOI2012网络 题解报告【LCT】

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

随机推荐

  1. SSM商城项目(三)

    1. 学习计划 1.商品类目选择 2.图片上传 a) 图片服务器FastDFS b) 图片上传功能实现 3.富文本编辑器的使用KindEditor 2. 商品类目选择 2.1. 原型 2.2. 功能分 ...

  2. Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.0.2:resources 在我的myeclipse中新建maven工程总出现这个问题

    只需在下图中更改代码 更改后是这样的: <plugin> <groupId>org.apache.maven.plugins</groupId> <artif ...

  3. GitLab 汉化

    汉化Gitlab Gitlab默认语言是英文,对于想加强英文的同学,建议继续使用英文,但要求使用中文,这里需要下载一个汉化包下载最新的汉化包: 下载最新的汉化包: [root@gitlab ~]# g ...

  4. jdbc连接模拟用户登陆密码判断

    package com.aaa.demo1; import com.aaa.utils.JdbcUtils; import java.sql.Connection; import java.sql.P ...

  5. 游戏AI技术 2

    [Unity3D人工智能编程精粹 2] 1.跟随领队行为. 用靠近(Seek)或追逐(Pursuit)实现跟随领队行为并不好.在Seek中,AI角色会被推向领队,最终与领队占据相同位置.而Pursui ...

  6. angular记录

    1. <h1>{{title}}</h1> 双花括号语法是 Angular 的插值绑定语法. 这个插值绑定的意思是把组件的 title 属性的值绑定到 HTML 中的 h1 标 ...

  7. Idea单元测试Junit Generator设置

    0. setting--->plugins--->brose repostories-->输入JUnitGenerator V2.0 1.junit generator自动生成测试代 ...

  8. data属性(The Data Attribute)

    HTML片段 <div id="myDiv" data-custom-attr="My Value"> 巴拉巴拉,lady 嘎嘎 </div& ...

  9. CSS float清除浮动

    解决高度塌陷的问题 – 清除浮动 CSS中有个讨论较多的话题就是如何清除浮动,清除浮动其实就一个目的,就是解决高度塌陷的问题.为什么会高度塌陷?什么时候会高度塌陷?塌陷原因是:元素含有浮动属性 – 破 ...

  10. pta l3-1(凑零钱)

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805054207279104 题意:给定n枚硬币的面值,需要支付 ...