AC日记——[ZJOI2012]网络 bzoj 2816
思路:
多个LCT;
代码:
#include <bits/stdc++.h>
using namespace std;
#define maxn 10005
#define ll long long
int val[maxn];
struct LinkCutTreeType {
int f[maxn],Max[maxn],ch[maxn][],rev[maxn],sta[maxn],top,cnt[maxn];
void updata(int now)
{
Max[now]=val[now];
if(ch[now][]) Max[now]=max(Max[now],Max[ch[now][]]);
if(ch[now][]) Max[now]=max(Max[now],Max[ch[now][]]);
}
void downdata(int now)
{
if(rev[now])
{
rev[now]^=,swap(ch[now][],ch[now][]);
if(ch[now][]) rev[ch[now][]]^=;
if(ch[now][]) rev[ch[now][]]^=;
}
}
bool isroot(int now)
{
return (ch[f[now]][]!=now)&&(ch[f[now]][]!=now);
}
void rotate(int now)
{
int fa=f[now],ffa=f[fa],l=(ch[fa][]==now),r=l^;
if(!isroot(fa)) ch[ffa][ch[ffa][]==fa]=now;
f[now]=ffa,f[fa]=now,ch[fa][l]=ch[now][r],ch[now][r]=fa;
if(ch[fa][l]) f[ch[fa][l]]=fa;updata(fa);
}
void splay(int now)
{
top=,sta[]=now;int fa,ffa;
for(int i=now;!isroot(i);i=f[i]) sta[++top]=f[i];
while(top) downdata(sta[top--]);
while(!isroot(now))
{
fa=f[now],ffa=f[fa];
if(!isroot(fa)) rotate(((ch[ffa][]==fa)^(ch[fa][]==now))?now:fa);
rotate(now);
}
updata(now);
}
void access(int now)
{
for(int i=;now;i=now,now=f[now]) splay(now),ch[now][]=i;
}
void makeroot(int now)
{
access(now),splay(now),rev[now]^=;
}
void cut(int x,int y)
{
makeroot(x),access(y),splay(y);
f[x]=,ch[y][]=,cnt[x]--,cnt[y]--;
}
void link(int x,int y)
{
makeroot(x),f[x]=y,splay(x),cnt[x]++,cnt[y]++;
}
bool iscon(int x,int y)
{
while(f[x]) x=f[x];
while(f[y]) y=f[y];
return x==y;
}
int query(int u,int v)
{
makeroot(u),access(v),splay(v);
return Max[v];
}
};
struct LinkCutTreeType lct[];
int n,m,c,k;
map<ll,int>Map;
inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'')Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
ll Mapped(int u,int v)
{
if(u>v) swap(u,v);
return (ll)u*n*n+v;
}
int main()
{
//freopen("data.txt","r",stdin);
freopen("networkzj.in","r",stdin);
freopen("networkzj.out","w",stdout);
in(n),in(m),in(c),in(k);int u,v,w,op;ll pos,id;
for(int i=;i<=n;i++) in(val[i]);
while(m--) in(u),in(v),in(w),Map[Mapped(u,v)]=w+,lct[w].link(u,v);
while(k--)
{
in(op);
if(op==)
{
in(u),in(val[u]);
for(int i=;i<c;i++) lct[i].splay(u);
}
if(op==)
{
in(u),in(v),in(w),id=Mapped(u,v),pos=Map[id]-;
if(pos<)
{
puts("No such edge.");
continue;
}
if(pos==w)
{
puts("Success.");
continue;
}
if(lct[w].cnt[u]>=||lct[w].cnt[v]>=)
{
puts("Error 1.");
continue;
}
if(lct[w].iscon(u,v))
{
puts("Error 2.");
continue;
}
lct[pos].cut(u,v),lct[w].link(u,v),Map[id]=w+;
puts("Success.");
}
if(op==)
{
in(w),in(u),in(v);
if(!lct[w].iscon(u,v))
{
puts("-1");
continue;
}
printf("%d\n",lct[w].query(u,v));
}
}
return ;
}
AC日记——[ZJOI2012]网络 bzoj 2816的更多相关文章
- AC日记——无线网络发射器选址 洛谷 P2038
题目描述 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的129 条东西向街道和129 条南北向街道所形成的网格状,并且相邻 ...
- AC日记——[Hnoi2017]影魔 bzoj 4826
4826 思路: 主席树矩阵加减+单调栈预处理: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 ...
- AC日记——[LNOI2014]LCA bzoj 3626
3626 思路: 离线操作+树剖: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #defin ...
- AC日记——[SCOI2009]游戏 bzoj 1025
[SCOI2009]游戏 思路: 和为n的几个数最小公倍数有多少种. dp即可: 代码: #include <bits/stdc++.h> using namespace std; #de ...
- AC日记——[HNOI2014]世界树 bzoj 3572
3572 思路: 虚树+乱搞: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 300005 #define ...
- AC日记——NOI2016区间 bzoj 4653
4653 思路: 线段树,指针滑动: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1000005 #def ...
- AC日记——Rmq Problem bzoj 3339
3339 思路: 恶心: 代码: #include <cstdio> #include <cstring> #include <iostream> #include ...
- AC日记——[HNOI2008]越狱 bzoj 1008
1008 思路: 越狱情况=总情况-不越狱情况: 代码: #include <cstdio> #include <cstring> #include <iostream& ...
- AC日记——[FJOI2007]轮状病毒 bzoj 1002
1002 思路: 打表找规律: dp[i]=dp[i-1]*3-dp[i-2]+2; 套个高精就a了: 代码: #include <cstdio> #include <cstring ...
随机推荐
- switch语法的盲点
switch语法在项目使用的频率很低,今天看到一个相关的例子引发一些思考,,同时自己也写了一些简单的例子如下: 实例1: int dayOfWeek = 5; switch (dayOfWeek){ ...
- Educational Codeforces Round 61 (Rated for Div. 2) D,F题解
D. Stressful Training 题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有n台电脑,每台电脑都有初始电量ai,也有一个 ...
- HRBUST 1819
石子合并问题--圆形版 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 61(27 users) Total Accepted: 26( ...
- ubuntu18.04server设置静态IP
16.04以后的版本配置静态IP是类似这样的文件 /etc/netplan/50-cloud-init.yaml 1.查询网卡名称 2.修改配置文件/etc/netplan/50-cloud-init ...
- 一个JAVA题引发的思考
转载自:http://www.cnblogs.com/heshan664754022/archive/2013/03/24/2979495.html 十年半山 今天在论坛闲逛的时候发现了一个很有趣的题 ...
- jQuery Lightbox效果插件Boxer
演示:http://www.jq22.com/yanshi1139 下载:链接: https://pan.baidu.com/s/1o8zaV2q 密码: 2ccy Boxer 是一款基于 jQuer ...
- Winform MD5
1:MD5 http://www.cmd5.com/ 字节数组----字符串 //将字节数组中每个元素按照指定的编码格式解析成字符串//直接将数组ToString()//将字节数组中的每个元素ToSt ...
- jq_常用开发模块
1.循环模块 var html = ""; $.each(data, function(k, v) { html += '<li>' + '<div>' + ...
- $.on方法与$.click()的区别
1.$.on("click") 支持动态元素绑定事件,该事件是绑定到document上,只要符合条件的元素即可绑定事件,同时$.on()可以绑定多个事件 on方法 on(event ...
- Linux简介——(一)
1. 常见操作系统 - 服务端操作系统 : linux.unix.windows server - 单机操作系统 : windows(dos .ucdos.win95.win98.win2000.xp ...