【Luogu】P2173网络(LCT)
这次坑我的是与或的结合顺序……
开十个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)的更多相关文章
- Luogu 2173 [ZJOI2012]网络 - LCT
Solution $LCT$ 直接上$QuQ$ 注意$cut$ 完 需要 $d[u + c * N]--$ 再 $link$, 不然会输出Error 1的哦 Code #include<cs ...
- Luogu P2173 [ZJOI2012]网络
题意 写的比较清楚,我就不解释了. \(\texttt{Data Range:}n\leq 10^4,m\leq 10^5,c\leq 10,k\leq 10^5\) 题解 注意到 \(c\) 的范围 ...
- ZJOI2012 网络——LCT相关题目
有一个无向图G,每个点有个权值,每条边有一个颜色.这个无向图满足以下两个条件: 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环,同色的环指相同颜色的边构成的环. 在这个图上,你 ...
- luoguP2173 [ZJOI2012]网络 LCT
链接 luogu 思路 颜色很少,开10个lct分别维护 if (Hash.count(make_pair(u, v)) && Hash[make_pair(u, v)] == col ...
- bzoj 2816: [ZJOI2012]网络 (LCT 建多棵树)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2816 题面: http://www.lydsy.com/JudgeOnline/upload ...
- BZOJ.2816.[ZJOI2012]网络(LCT)
题目链接 BZOJ 洛谷 对每种颜色维护一个LCT,保存点之间的连接关系. 修改权值A[x]和所有Max[x]都要改: 修改边的颜色先枚举所有颜色,看是否在某种颜色中有边,然后断开.(枚举一遍就行啊 ...
- BZOJ2816:[ZJOI2012]网络(LCT)
Description 有一个无向图G,每个点有个权值,每条边有一个颜色.这个无向图满足以下两个条件: 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环,同色的环指相同颜色的边构 ...
- 【luogu P3376 网络最大流】 模板
题目链接:https://www.luogu.org/problemnew/show/P3376 #include <iostream> #include <cstdio> # ...
- Luogu P4299 首都 LCT
既然是中文题目,这里便不给题意. 分析: 这个题的做法据说是启发式合并? 但是我不会啊…… 进入正题,LCT是怎样做掉这道题的.记得在前面的一篇<大融合>的题解中,介绍过LCT维护子树信息 ...
随机推荐
- java设计模式——建造者模式
一. 定义与类型 定义:将一个复杂对象的构建与它的表示分离,使用同样的构建过程可以创建不同的表示 用户只需制定需要建造的类型就可以得到它们,建造过程以及细节不需要知道 类型:创建型 建造者模式与工厂模 ...
- PHP implode() 函数
转自:http://www.w3school.com.cn/php/func_string_implode.asp 语法 implode(separator,array) 参数 描述 separato ...
- vue列表过渡效果
<transition-group></transition-group> ① 列表 <transition-group> </transition-grou ...
- Oracle分页抽数存储过程
--outTotal是需要返回的总数,v_loginUserId是传入的登录人ID,抽取他的客户,v_CurrPage是传入的第几页,v_pageSize传入的每页数据条数. ) FROM tb_cu ...
- KVM修改虚机网卡模式:由NAT模式改为Bridge模式
1)关闭虚机# virsh shutdown vm1 2)编辑虚机配置文件# virsh edit vm1 <interface type='default'> 改为<int ...
- nodejs mysql模块简单封装
nodejs 简单的封装一些mysql模块 实现一个方法根据不同传参进行增删改查 首先要 npm install mysql 代码如下 function data(objHost,sql,callba ...
- SummerVocation_Learning--java的String类运用
题目: 编写一个程序,输出一个字符串中的大写字母数,小写字母数,及其它字母数. 思路1: 可以先遍历整个字符串,在判断每个字符的类型. public class TestString { public ...
- 洛谷P1481 魔族密码(LIS)
题意 题目链接 给出一堆字符串,若一个串是另一个串的前缀 ,那么它们可以连接在一起 问最大的链接长度 Sol LIS沙比提其实是做完了才看出是LIS #include<cstdio> #i ...
- 爬虫学习(三)——get请求参数解析
get请求: 用户输入搜索的内容,发送请求,将请求的内容保存起来. get请求的本质是在地址栏中输入参数进行的一种请求方式. 解析参数使用urllib.parse impo ...
- 获取页面URL参数值
JavaScript function GetParams(urlAddress) { var i, strLength, str, keyName, keyValue, params = {}, u ...