BZOJ2594:水管局长数据加强版
Description
Input
Output
Sample Input
1 2 2
2 3 3
3 4 2
1 4 2
1 1 4
2 1 4
1 1 4
Sample Output
3
HINT
【原题数据范围】
N ≤ 1000
M ≤ 100000
Q ≤ 100000
测试数据中宣布报废的水管不超过5000条;且任何时候我们考虑的水管网络都是连通的,即从任一结点A必有至少一条水管路径通往任一结点B。
【加强版数据范围】
N ≤ 100000
M ≤ 1000000
Q ≤ 100000
任何时候我们考虑的水管网络都是连通的,即从任一结点A必有至少一条水管路径通往任一结点B。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,Q,top;
int f[];
int fa[],c[][],s[];
int mx[],val[];
bool rev[];
struct edge{int u,v,w,id;bool d;}e[];
struct que{int f,x,y,ans,id;}q[];
bool operator<(edge a,edge b)
{
return a.u<b.u||(a.u==b.u&&a.v<b.v);
}
bool cmp(edge a,edge b)
{
return a.w<b.w;
}
bool cmp2(edge a,edge b)
{
return a.id<b.id;
}
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
int find(int u,int v)
{
int l=,r=m;
while(l<=r)
{
int mid=(l+r)>>;
if(e[mid].u<u||(e[mid].u==u&&e[mid].v<v))l=mid+;
else if(e[mid].u==u&&e[mid].v==v)return mid;
else r=mid-;
}
}
bool isroot(int x)
{
return c[fa[x]][]!=x&&c[fa[x]][]!=x;
}
void update(int x)
{
int l=c[x][],r=c[x][];
mx[x]=x;
if(val[mx[l]]>val[mx[x]])mx[x]=mx[l];
if(val[mx[r]]>val[mx[x]])mx[x]=mx[r];
}
void rotate(int x)
{
int y=fa[x],z=fa[y],l,r;
if(c[y][]==x)l=;else l=;r=l^;
if(!isroot(y))
{
if(c[z][]==y)c[z][]=x;else c[z][]=x;
}
fa[x]=z;fa[y]=x;fa[c[x][r]]=y;
c[y][l]=c[x][r];c[x][r]=y;
update(y);update(x);
}
void pushdown(int x)
{
int l=c[x][],r=c[x][];
if(rev[x])
{
rev[x]^=;
rev[l]^=;rev[r]^=;
swap(c[x][],c[x][]);
}
}
void splay(int x)
{
top=;s[++top]=x;
for(int i=x;!isroot(i);i=fa[i])
s[++top]=fa[i];
for(int i=top;i;i--)
pushdown(s[i]);
while(!isroot(x))
{
int y=fa[x],z=fa[y];
if(!isroot(y))
{
if(c[y][]==x^c[z][]==y)rotate(x);
else rotate(y);
}
rotate(x);
}
}
void access(int x)
{
int t=;
while(x)
{
splay(x);c[x][]=t;update(x);t=x;x=fa[x];
}
}
void makeroot(int x)
{
access(x);splay(x);rev[x]^=;
}
void link(int x,int y)
{
makeroot(x);fa[x]=y;
}
void cut(int x,int y)
{
makeroot(x);access(y);splay(y);c[y][]=fa[x]=;
}
int query(int x,int y)
{
makeroot(x);access(y);splay(y);return mx[y];
}
int main()
{
n=read();m=read();Q=read();
for(int i=;i<=n;i++)f[i]=i;
for(int i=;i<=m;i++)
{
e[i].u=read(),e[i].v=read(),e[i].w=read();
if(e[i].u>e[i].v)swap(e[i].u,e[i].v);
}
sort(e+,e+m+,cmp);
for(int i=;i<=m;i++)
{
e[i].id=i;
val[n+i]=e[i].w;
mx[n+i]=n+i;
}
sort(e+,e+m+);
for(int i=;i<=Q;i++)
{
q[i].f=read(),q[i].x=read(),q[i].y=read();
if(q[i].f==)
{
if(q[i].x>q[i].y)swap(q[i].x,q[i].y);
int t=find(q[i].x,q[i].y);
e[t].d=;q[i].id=e[t].id;
}
}
sort(e+,e+m+,cmp2);
int tot=;
for(int i=;i<=m;i++)
if(!e[i].d)
{
int u=e[i].u,v=e[i].v,x=getf(u),y=getf(v);
if(x!=y)
{
f[x]=y;
link(u,i+n);link(v,i+n);
tot++;
if(tot==n-)break;
}
}
for(int i=Q;i;i--)
{
if(q[i].f==)
q[i].ans=val[query(q[i].x,q[i].y)];
else
{
int u=q[i].x,v=q[i].y,k=q[i].id;
int t=query(u,v);
if(e[k].w<val[t])
{
cut(e[t-n].u,t);cut(e[t-n].v,t);
link(u,k+n);link(v,k+n); }
}
}
for(int i=;i<=Q;i++)
if(q[i].f==)printf("%d\n",q[i].ans);
return ;
}
BZOJ2594:水管局长数据加强版的更多相关文章
- BZOJ2594: [Wc2006]水管局长数据加强版
题解: 裸LCT+离线+二分+MST... 代码:(几乎摘抄自hzwer) #include<cstdio> #include<cstdlib> #include<cma ...
- [bzoj2594][Wc2006]水管局长数据加强版 (lct)
论蒟蒻的自我修养T_T.. 和noi2014魔法森林基本一样...然而数据范围大得sxbk...UPD:这题如果用lct判联通的话可能会被卡到O(mlogm)..所以最好还是用并查集吧 一开始数组开太 ...
- bzoj 2594: [Wc2006]水管局长数据加强版 动态树
2594: [Wc2006]水管局长数据加强版 Time Limit: 25 Sec Memory Limit: 128 MBSubmit: 934 Solved: 291[Submit][Sta ...
- BZOJ 2594: [Wc2006]水管局长数据加强版( LCT )
离线然后就是维护加边的动态MST, Link cut tree秒掉..不过我写+调了好久...时间复杂度O(NlogN + MlogM) ------------------------------- ...
- BZOJ 2594: [Wc2006]水管局长数据加强版 [LCT kruskal]
2594: [Wc2006]水管局长数据加强版 Time Limit: 25 Sec Memory Limit: 128 MBSubmit: 2917 Solved: 918[Submit][St ...
- BZOJ_2594_[Wc2006]水管局长数据加强版_LCT
BZOJ_2594_[Wc2006]水管局长数据加强版_LCT Description SC省MY市有着庞大的地下水管网络,嘟嘟是MY市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供 ...
- BZOJ 2594 【WC2006】 水管局长数据加强版
题目链接:水管局长数据加强版 好久没写博客了…… 上次考试的时候写了一发LCT,但是写挂了……突然意识到我已经很久没有写过LCT了,于是今天找了道题来练练手. 首先,LCT这里不讲.这道题要求支持动态 ...
- BZOJ2594 [Wc2006]水管局长数据加强版 【LCT维护最小生成树】
题目 SC省MY市有着庞大的地下水管网络,嘟嘟是MY市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供水公司可能要将一定量的水从x处送往y处,嘟嘟需要为供水公司找到一条从A至B的水管的 ...
- [WC 2006]水管局长数据加强版
Description SC省MY市有着庞大的地下水管网络,嘟嘟是MY市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供水公司可能要将一定量的水从x处送往y处,嘟嘟需要为供水公司找到一 ...
随机推荐
- 转载:ASP.NET Core 在 JSON 文件中配置依赖注入
在以前的 ASP.NET 4+ (MVC,Web Api,Owin,SingalR等)时候,都是提供了专有的接口以供使用第三方的依赖注入组件,比如我们常用的会使用 Autofac.Untiy.Stri ...
- 《软件调试修炼之道》Part 1(CH1~5)读书笔记 PB16110698 第八周(~4.26)
编程中,调试几乎是必不可少的,一劳永逸.一次完成预想功能而完全不出bug的情况凤毛麟角,出现bug→调试→再出现bug→再调试……基本是软件工程中的常态.可以说,软件调试是每个coder的必修课,而& ...
- JS对象 indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。
返回指定的字符串首次出现的位置 indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置. 语法 stringObject.indexOf(substring, startpos) 参 ...
- JS对象 返回/设置时间方法 get/setTime() 返回/设置时间,单位毫秒数 一小时为:60*60*1000
返回/设置时间方法 get/setTime() 返回/设置时间,单位毫秒数,计算从 1970 年 1 月 1 日零时到日期对象所指的日期的毫秒数. 如果将目前日期对象的时间推迟1小时,代码如下: &l ...
- windows使用cmd查看、杀死进程
查看某个进程: netstat -ano | findstr 端口号 杀死某个进程: taskkill /f /pid 进程号
- C# 创建DataTable并添加行和列
DataTable dt=new DataTable dt.Columns.Add("numview", typeof(Int32)); dt.Columns.Add(" ...
- error while loading shared libraries: lib*.so: cannot open shared object file: No such file or directory
动态库的搜索路径搜索的先后顺序是: 1.编译目标代码时指定的动态库搜索路径; 2.环境变量LD_LIBRARY_PATH指定的动态库搜索路径: 比如export LD_LIBRARY_PATH=/us ...
- java 自加和短路问题 几个例子
x++可以看做一个独立的变量 如int a=x++;x的值先把他赋值给x++然后X++再赋值a,最后x再自加1 ++X int a=++ X 先自加1 x的值赋值给++x然后++x再赋值a ...
- jmeter+ant+jenkins 搭建接口自动化测试环境
过程参考:http://www.cnblogs.com/lxs1314/p/7487066.html 1. 安装ant 2. 安装jenkins 遇到问题: 启动Tomcat后,访问http://lo ...
- EL fmt标签
c:formate 表达式需要传入的对象为date