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的更多相关文章

  1. AC日记——无线网络发射器选址 洛谷 P2038

    题目描述 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的129 条东西向街道和129 条南北向街道所形成的网格状,并且相邻 ...

  2. AC日记——[Hnoi2017]影魔 bzoj 4826

    4826 思路: 主席树矩阵加减+单调栈预处理: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 ...

  3. AC日记——[LNOI2014]LCA bzoj 3626

    3626 思路: 离线操作+树剖: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #defin ...

  4. AC日记——[SCOI2009]游戏 bzoj 1025

    [SCOI2009]游戏 思路: 和为n的几个数最小公倍数有多少种. dp即可: 代码: #include <bits/stdc++.h> using namespace std; #de ...

  5. AC日记——[HNOI2014]世界树 bzoj 3572

    3572 思路: 虚树+乱搞: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 300005 #define ...

  6. AC日记——NOI2016区间 bzoj 4653

    4653 思路: 线段树,指针滑动: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1000005 #def ...

  7. AC日记——Rmq Problem bzoj 3339

    3339 思路: 恶心: 代码: #include <cstdio> #include <cstring> #include <iostream> #include ...

  8. AC日记——[HNOI2008]越狱 bzoj 1008

    1008 思路: 越狱情况=总情况-不越狱情况: 代码: #include <cstdio> #include <cstring> #include <iostream& ...

  9. AC日记——[FJOI2007]轮状病毒 bzoj 1002

    1002 思路: 打表找规律: dp[i]=dp[i-1]*3-dp[i-2]+2; 套个高精就a了: 代码: #include <cstdio> #include <cstring ...

随机推荐

  1. 用户登录拦截器查询到登录用户后如何将用户信息传递到后面的Controller

    taotao创建订单代码中之前忘了加入用户信息,那么加上呢? 分析:用户创建订单的时候,我们会强制要求用户先登录,也就是说,创建订单的Controller执行时,一定是用户已经登录了的,而用户只要登录 ...

  2. STL之七:STL各种容器的使用时机详解

    转载于:http://blog.csdn.net/longshengguoji/article/details/8550235 C++标准程序库提供了各具特长的不同容器.现在的问题是:该如何选择最佳的 ...

  3. springboot的application.properties与.yml的区别

    现在我们的application.properties文件内容是: server.port=8090 server.session-timeout=30 server.context-path= se ...

  4. margin和padding

    一.margin基础语法与结构 1.margin语法 Margin:10px Margin的值是数字+html单位,同时也可以为auto(自动.自适应) 2.应用结构 Div{margin:10px} ...

  5. 第01篇 说一下Setting,我一直没有讲过

        settings 调整 settings 中的设置是非常关键的,它们会改变 MyBatis 的运行时行为.下表描述了设置中各项的意图.默认值等. 设置参数 描述 有效值 默认值 cacheEn ...

  6. linux tar指定文件到指定目录

    项目需求:从远处拷贝压缩文件到本地后并解压,解压后的部分文件拷贝并重命名到其他目录 需求拆分:1.拷贝文件 2.解压文件 3.批量重命名 步骤一查看:http://www.cnblogs.com/dd ...

  7. spring常用管理bean注解

    spring提供了多个注解声明Bean为spring管理的Bean @Controller 声明此类是一个MVC类,通常与@RequestMapping一起使用 @Controller @Reques ...

  8. UVA 1363 Joseph's Problem

    https://vjudge.net/problem/UVA-1363 n 题意:求 Σ  k%i i=1 除法分块 如果 k/i==k/(i+1)=p 那么 k%(i+1)=k-(i+1)*p= k ...

  9. [洛谷P1858] 多人背包

    洛谷题目链接:多人背包 题目描述 求01背包前k优解的价值和 输入输出格式 输入格式: 第一行三个数K.V.N 接下来每行两个数,表示体积和价值 输出格式: 前k优解的价值和 输入输出样例 输入样例# ...

  10. Item 9 覆盖equals时总要覆盖hashCode

    为什么覆盖equals时,总要覆盖hashCode?   原因是,根据Object规范: 如果两个对象根据equals(Object)方法比较是相等的,那么调用这两个对象中任意一个对象的hashCod ...