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$板子题,直接维护 ...
随机推荐
- JS对象 编程练习 某班的成绩出来了,现在老师要把班级的成绩打印出来。 效果图: XXXX年XX月X日 星期X--班级总分为:81
编程练习 某班的成绩出来了,现在老师要把班级的成绩打印出来. 效果图: XXXX年XX月X日 星期X--班级总分为:81 格式要求: 1.显示打印的日期. 格式为类似"XXXX年XX月XX日 ...
- ReadWriteLock 如何使用?
QReadWriteLock从名字看就知道是读写锁的意思.和QMutex一样,QReadWriteLock也是线程同步的一种工具.那么它有什么用呢?和QMutex又有什么区别呢?写个例子瞧一瞧. 特点 ...
- bzoj1031题解
[解题思路] 将原串复制一份拼接到原串后作为处理串,可以对处理串的前一半后缀排序,即可得出顺序.复杂度O(Llog2L). [参考代码] 也是naive的时候写的..后缀数组居然是用桶排求的.. #p ...
- kafka集群安装和使用
kafka(1)kafka是一个分布式的消息缓存系统(2)kafka集群中的服务器都叫做broker(3)kafka有两类客户端,一个叫做producer(消息生产者),一类叫做consumer(消息 ...
- php-fpm 服务
编译安装PHP的时候已经加入了--enable-fpm 在此基础上启动php-fpm服务 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/p ...
- NOIp2018集训test-9-7(pm) (联考一day1)
又被辉神吊打了.今天不仅被辉神李巨吊打,还给基本上给全班垫底了. 看到T3就知道是十进制快速幂,全机房考试的当时应该就我会,结果我tm没找到递推. Orz lyc BM直接水过,Orz wys六个fo ...
- Metasploit 模块和位置
Metasploit Framework由许多的模块组成的. 一.Exploits(漏洞模块) 定义为使用“有效载荷(payloads)”的模块 没有“有效载荷”的攻击是辅助模块 二.Payloads ...
- [00]APUE:GCC / GDB / Makefile
http://blog.csdn.net/haoel/article/category/9197 http://blog.csdn.net/haoel/article/details/2886 生成 ...
- bagging和boosting以及rand-forest
bagging: 让该学习算法训练多轮,每轮的训练集由从初始的训练集中随机取出的n个训练样本组成,某个初始训练样本在某轮训练集中可以出现多次或根本不出现,训练之后可得到一个预测函数序列h_1,⋯ ⋯h ...
- 运行mybatis项目,运行测试类,点击test后,出现Cannot start compilation: the output path is not specified for module "前......
Cannot start compilation: the output path is not specified for module "前 后来发现是在pom.xml右击,有个+号,把 ...