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$板子题,直接维护 ...
随机推荐
- 【转】移动前端开发之viewport的深入理解
原文链接:https://blog.csdn.net/u012402190/article/details/70172371 笔记 (20180919,目前暂且只看一部分)
- Struts2开发环境搭建
eclipse配置struts2开发环境: 1.导入jar包:复制Struts\apps\struts2-blank\WEB-INF\lib下的所有jar包到当前项目的lib文件夹下 2.在web.x ...
- C:\Windows\System32\drivers\etc中的hosts文件
这个文件是根据TCP/IP for Windows 的标准来工作的,它的作用是包含IP地址和Host name(主机名)的映射关系,是一个映射IP地址和Host name(主机名)的规定,规定要求每段 ...
- jq-demo-放大镜
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- yum 安装pip
centos7 没有python-pip包就执行命令 yum -y install epel-release 执行成功之后,再次执行yum install python-pip 对安装好的pip进行升 ...
- Q:微信小程序一次性订阅消息(前台收集)
说明:官方文档(https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/subscribe-message.ht ...
- tp5 查询本年、本月、本周的方法
tp5自带了一些查询的方法,今天说一下查询本年.本月以及本周的方法 whereTime()//此方法代替了between and 方法 实际用法如下: ->whereTime('时间字段','y ...
- 整理delphi及整理原则
回看delphi使用的人也不多,但一直觉得这门语言挺好的,所以一直在用,在很多方面也给了很多帮助和启示 加上delphi的学习文件也确实比较少,故收集起来也不容易.今日,重新整理一下delphi ,一 ...
- JS分支结构与循环结构
1.分支结构 ①if语句 语法结构 if (/* 条件表达式 */) { // 执行语句 } if (/* 条件表达式 */){ // 成立执行语句 } else { // 否则执行语句 } ...
- sql语句创建表
create table `search_custom_mall` ( `id` ) NOT NULL PRIMARY KEY AUTO_INCREMENT, `uid` ) NOT NULL, `n ...