2816: [ZJOI2012]网络
把一个点拆成c个即可
浪费时间的水题...
//Achen
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
const int N=2e5+;
typedef long long LL;
typedef double db;
using namespace std;
int n,m,c,q,cnt[N][];
LL v[N]; template<typename T> void read(T &x) {
char ch=getchar(); x=; T f=;
while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
if(ch=='-') f=-,ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
} map<LL,int>col;
LL get(int x,int y) { return (LL)x*+y; } int p[N],ch[N][],flip[N];
LL mx[N];
#define lc ch[x][0]
#define rc ch[x][1]
void update(int x) { mx[x]=max(max(mx[lc],mx[rc]),v[x]); } void down(int x) {
if(!flip[x]) return;
swap(lc,rc);
flip[lc]^=;
flip[rc]^=;
flip[x]^=;
} int isroot(int x) { return ch[p[x]][]!=x&&ch[p[x]][]!=x; } void rotate(int x) {
int y=p[x],z=p[y],l=(x==ch[y][]),r=l^;
if(!isroot(y)) ch[z][y==ch[z][]]=x; p[x]=z;
ch[y][l]=ch[x][r]; p[ch[x][r]]=y;
ch[x][r]=y; p[y]=x;
update(y); update(x);
} void splay(int x) {
static int g[N],top=,tp;
for(tp=x;!isroot(tp);tp=p[tp]) g[++top]=tp;
g[++top]=tp;
while(top) down(g[top--]);
for(;!isroot(x);rotate(x)) {
int y=p[x],z=p[y];
if(!isroot(y)) ((x==ch[y][])^(y==ch[z][]))?rotate(x):rotate(y);
}
} void access(int x) {
for(int t=;x;x=p[t=x]) {
splay(x);
rc=t;
update(x);
}
} int find_root(int x) {
access(x);
splay(x);
while(lc) x=lc;
return x;
} void newroot(int x) {
access(x);
splay(x);
flip[x]^=;
} void lik(int x,int y) {
newroot(x);
splay(x);
splay(y);
p[x]=y;
} void cut(int x,int y) {
newroot(x);
access(y);
splay(y);
if(ch[y][]==x) ch[y][]=p[x]=;
update(y);
} void change(int x,int y) {
splay(x);
v[x]=y;
update(x);
} void qry(int x,int y) {
if(find_root(x)!=find_root(y)) {
puts("-1"); return;
}
newroot(x);
access(y);
splay(y);
printf("%lld\n",mx[y]);
} #define DEBUG
int main() {
#ifdef DEBUG
freopen("std.in","r",stdin);
//freopen(".out","w",stdout);
#endif
read(n); read(m); read(c); read(q);
For(i,,n) {
read(v[i]);
For(j,,c-) v[i+j*n]=v[i];
}
For(i,,m) {
int u,v,w;
read(u); read(v); read(w); w++;
cnt[u][w]++; cnt[v][w]++;
col[get(u,v)]=col[get(v,u)]=w;
lik(u+(w-)*n,v+(w-)*n);
}
For(ti,,q) {
int o,x,y,u,v,nw;
read(o);
if(o==) {
read(x); LL xx; read(xx);
For(i,,c)
change(x+(i-)*n,xx);
}
else if(o==) {
read(u); read(v); read(nw); nw++;
int w=col[get(u,v)];
if(!w) { puts("No such edge."); continue; }
if(w==nw) { puts("Success."); continue; }
if(cnt[u][nw]+>||cnt[v][nw]+>) { puts("Error 1."); continue; }
if(find_root((nw-)*n+u)==find_root((nw-)*n+v)) { puts("Error 2."); continue; }
col[get(u,v)]=col[get(v,u)]=nw;
cnt[u][w]--; cnt[v][w]--;
cnt[u][nw]++; cnt[v][nw]++;
cut((w-)*n+u,(w-)*n+v);
lik((nw-)*n+u,(nw-)*n+v);
puts("Success.");
}
else {
read(nw); read(u); read(v);
qry(nw*n+u,nw*n+v);
}
}
return ;
}
2816: [ZJOI2012]网络的更多相关文章
- bzoj 2816: [ZJOI2012]网络 (LCT 建多棵树)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2816 题面: http://www.lydsy.com/JudgeOnline/upload ...
- bzoj 2816: [ZJOI2012]网络(splay)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2816 [题意] 给定一个无向图,满足条件:从一个节点出发的同色边不超过2条,且不存在同 ...
- 【刷题】BZOJ 2816 [ZJOI2012]网络
Description http://www.lydsy.com/JudgeOnline/upload/zjoi2012.pdf Solution 维护树上联通块的信息,支持动态加边删边 LCT 总共 ...
- BZOJ.2816.[ZJOI2012]网络(LCT)
题目链接 BZOJ 洛谷 对每种颜色维护一个LCT,保存点之间的连接关系. 修改权值A[x]和所有Max[x]都要改: 修改边的颜色先枚举所有颜色,看是否在某种颜色中有边,然后断开.(枚举一遍就行啊 ...
- 洛谷 2173 BZOJ 2816 [ZJOI2012]网络
[题解] 明显的LCT模板题,c种颜色就开c棵LCT好了.. #include<cstdio> #include<algorithm> #define N 100010 #de ...
- 洛谷 P2173 [ZJOI2012]网络 解题报告
P2173 [ZJOI2012]网络 题目描述 有一个无向图G,每个点有个权值,每条边有一个颜色.这个无向图满足以下两个条件: 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环, ...
- AC日记——[ZJOI2012]网络 bzoj 2816
2816 思路: 多个LCT: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 10005 #define l ...
- bzoj千题计划223:bzoj2816: [ZJOI2012]网络
http://www.lydsy.com/JudgeOnline/problem.php?id=2816 每种颜色搞一个LCT 判断u v之间有边直接相连: 如果u和v之间有边相连,那么他们的深度相差 ...
- bzoj2816 [ZJOI2012]网络
Description http://www.lydsy.com/JudgeOnline/upload/zjoi2012.pdf 正解:$link-cut \ tree$. $LCT$板子题,直接维护 ...
随机推荐
- JQ基本
jQuery的入口函数: 特点:1. 等着DOM结构渲染完毕即可执行内部代码,不必等到所有外部资源加载完毕,jQuery帮我们完成了封装. 2. 相当于原生js中的DOMContentLoaded. ...
- SpringMVC和spring常见面试题总结
1.什么是Spring MVC ?简单介绍下你对springMVC的理解? Spring MVC是一个基于Java的实现了MVC设计模式的请求驱动类型的轻量级Web框架,通过把Model,View,C ...
- ElementUI的使用
一.安装 1.安装 在项目目录下执行 npm i element-ui -S 2.引入 在 main.js 中写入以下内容: import ElementUI from 'element-ui'; i ...
- 安装percona-toolkit.rpm时候报错:perl(Time::HiRes) is needed by percona-toolkit-2.2.16-1.noarch
1.安装percona-toolkit.rpm时候报错: warning: percona-toolkit.rpm: Header V4 DSA/SHA1 Signature, key ID cd2e ...
- PHP 实现斐波那契数列
使用循环实现 <?php $arr[1] = 1; for($i = 2;$i < 100;$i++) { $arr[$i] = $arr[$i-1] + $arr[$i-2]; } ec ...
- php 使用fseek指针读取大文件日志
function text($fp,$n,$b=5) { if($n>0){ $p = $n+1; $lines = array(); while(count($lines)< =$n){ ...
- lua的运算符
1.赋值运算符 --赋值 str="helllo".."world" print(str) a,b=10,20 print(a,b) c,d,e=1,2 pri ...
- NX二次开发-UFUN编辑添加哪些图层UF_LAYER_edit_category_layer
1 NX11+VS2013 2 3 #include <uf.h> 4 #include <uf_layer.h> 5 6 7 UF_initialize(); 8 9 //创 ...
- csp-s模拟测试91
csp-s模拟测试91 倒悬吃屎的一套题. $T1$认真(?)分析题意发现复杂度不能带$n$(?),计划直接维护答案,考虑操作对答案的影响,未果.突然发现可以动态开点权值线段树打部分分,后来$Tm$一 ...
- DZY LOVES MATH (莫比乌斯反演)
OK!开始更新莫比乌斯反演 先看了一下数据范围,嗯,根据\(jiry\)老师的真言,我们一定是可以筛一遍然后用根号或者是\(log\)的算法. 题目思路挺简单,就是把原始的式子化成: \(\sum_{ ...