传送们

把一个点拆成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]网络的更多相关文章

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

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

  2. bzoj 2816: [ZJOI2012]网络(splay)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2816 [题意] 给定一个无向图,满足条件:从一个节点出发的同色边不超过2条,且不存在同 ...

  3. 【刷题】BZOJ 2816 [ZJOI2012]网络

    Description http://www.lydsy.com/JudgeOnline/upload/zjoi2012.pdf Solution 维护树上联通块的信息,支持动态加边删边 LCT 总共 ...

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

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

  5. 洛谷 2173 BZOJ 2816 [ZJOI2012]网络

    [题解] 明显的LCT模板题,c种颜色就开c棵LCT好了.. #include<cstdio> #include<algorithm> #define N 100010 #de ...

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

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

  7. AC日记——[ZJOI2012]网络 bzoj 2816

    2816 思路: 多个LCT: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 10005 #define l ...

  8. bzoj千题计划223:bzoj2816: [ZJOI2012]网络

    http://www.lydsy.com/JudgeOnline/problem.php?id=2816 每种颜色搞一个LCT 判断u v之间有边直接相连: 如果u和v之间有边相连,那么他们的深度相差 ...

  9. bzoj2816 [ZJOI2012]网络

    Description http://www.lydsy.com/JudgeOnline/upload/zjoi2012.pdf 正解:$link-cut \ tree$. $LCT$板子题,直接维护 ...

随机推荐

  1. (Struts2学习系列二)Struts2动态方法调用:指定method属性

    紧接着上一篇,在HelloWorldAction.java中添加add和update方法: public class HelloWorldAction extends ActionSupport{ p ...

  2. ASP.NET MVC 解决账号重复登录问题

    解决重复登录 用到了 .net 身份票证 和Global全局处理文件 第一步 登录方法  传入用户名 private void GetOnline(string Name) { Hashtable S ...

  3. cin,cout优化

    https://www.cnblogs.com/PrayG/p/5749832.html ios_base::sync_with_stdio(0);    cin.tie(0); 涨知识了

  4. JavaWeb 二维码

    说明 相关包 zxing-core3.3 zxing-javase3.3 junit4.12 POM文件 <dependency> <groupId>com.google.zx ...

  5. leetcood学习笔记-39-组合总和

    题目描述: 方法一: class Solution: def combinationSum(self, candidates, target): """ :type ca ...

  6. PHP面向对象----- 类的自动加载

    1.类的自动加载 spl_autoload_register函数 test.php <?php spl_autoload_register('autoload'); // require_onc ...

  7. Kotlin -help

    { kotlin: run Kotlin programs, scripts or REPL. Usage: kotlin <options> <command> <ar ...

  8. 25 面向对象设计实例——基于PCL点云库的通用工具开发

    0 引言 问题背景:pcl中提供了大量工具,用于对点云和三角面片文件进行处理和显示.在研究中,存在很多简易的需求,比如点云坐标转换,点云的打开显示以及同步显示,点云的最小包络求解,点云的格式转换等等. ...

  9. Intervals POJ - 3680

    传送门 给定数轴上n个带权区间$[l_i,r_i]$,权值为$w_i$ 选出一些区间使权值和最大,且每个点被覆盖次数不超过k次. 离散+拆点,最大费用可行流(跑到费用为负为止) 第一部分点按下标串起来 ...

  10. [JZOJ 5812] 区间

    题意:求经过多少次操作可以使得序列达到给定状态. 思路: 好像和\(CF\)某次比赛的题差不多啊... 差分统计每个点的值,将临近的\(+1\)和\(-1\)匹配即可. #include <bi ...