来自FallDream的博客,未经允许,请勿转载,谢谢。


给定一张无向图,有点权,要支持单点修改点权和询问从一个点到另一个点不重复经过节点的路径上点权最小值的最小值。

n,m<=10^5

考虑求出图的点双连通分量,然后每个点向所有包含他的点双连边,这样我们可以得到一棵树。

询问就变成了询问与树上两点间路径上的点相邻的点中权值的最小值。

我们考虑对每个点双开一个堆,把所有儿子的信息扔进去。这样但点修改只需要修改它父亲那个点双就行了。

然后用树剖+线段树来支持查询即可。注意特判lca的父亲节点。

复杂度O(nlog^2n)

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<vector>
  5. #include<queue>
  6. #include<map>
  7. #define P(x,y) make_pair(min(x,y),max(x,y))
  8. #define pa pair<int,int>
  9. #define MN 200000
  10. #define N 262144
  11. using namespace std;
  12. inline int read()
  13. {
  14. int x=,f=;char ch=getchar();
  15. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  16. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  17. return x*f;
  18. }
  19. pa q[MN*+];map<pa,bool> mp;vector<int> v[MN+];priority_queue<pa,vector<pa>,greater<pa> > s[MN+];
  20. int n,m,Q,tp=,b[MN+],head[MN+],dfn[MN+],low[MN+],mark[MN+],dn=,cnt=,size[MN+];
  21. int fa[MN+],w[MN+],vis[MN+],num=,bel[MN+],dep[MN+],top[MN+],mx[MN+],T[N*+];
  22. struct edge{int to,next;}e[MN*+];
  23. inline void ins(int f,int t)
  24. {
  25. e[++cnt]=(edge){t,head[f]};head[f]=cnt;
  26. e[++cnt]=(edge){f,head[t]};head[t]=cnt;
  27. }
  28. inline void Ins(int f,int t)
  29. {
  30. v[f].push_back(t);
  31. v[t].push_back(f);
  32. }
  33. void Tarjan(int x,int fa)
  34. {
  35. dfn[x]=low[x]=++dn;int son=;
  36. for(int i=head[x];i;i=e[i].next)
  37. if(e[i].to!=fa)
  38. {
  39. if(!dfn[e[i].to])
  40. {
  41. ++son;
  42. q[++tp]=make_pair(x,e[i].to),Tarjan(e[i].to,x);
  43. low[x]=min(low[x],low[e[i].to]);
  44. if(low[e[i].to]>=dfn[x])
  45. {
  46. b[x]=;++num;
  47. while(q[tp+]!=make_pair(x,e[i].to))
  48. {
  49. int a=q[tp].first,b=q[tp].second;
  50. if(bel[a]!=num) Ins(a,num+n);
  51. if(bel[b]!=num) Ins(b,num+n);
  52. --tp;bel[a]=num;bel[b]=num;
  53. }
  54. }
  55. }
  56. else
  57. {
  58. low[x]=min(low[x],dfn[e[i].to]);
  59. if(dfn[x]>dfn[e[i].to]) q[++tp]=make_pair(x,e[i].to);
  60. }
  61. }
  62. if(son==&&!fa) b[x]=;
  63. }
  64. void Pre(int x,int f)
  65. {
  66. fa[x]=f;size[x]=;mx[x]=;
  67. for(int i=;i<v[x].size();++i)
  68. if(v[x][i]!=f)
  69. {
  70. dep[v[x][i]]=dep[x]+;
  71. Pre(v[x][i],x);
  72. size[x]+=size[v[x][i]];
  73. if(size[v[x][i]]>size[mx[x]]) mx[x]=v[x][i];
  74. }
  75. }
  76.  
  77. void Dfs(int x,int Tp)
  78. {
  79. top[x]=Tp;dfn[x]=++dn;
  80. if(mx[x]) Dfs(mx[x],Tp);
  81. for(int i=;i<v[x].size();++i)
  82. if(v[x][i]!=mx[x]&&v[x][i]!=fa[x])
  83. Dfs(v[x][i],v[x][i]);
  84. }
  85. void Renew(int x,int k){for(T[x+=N]=k;x>>=;)T[x]=min(T[x<<],T[x<<|]);}
  86. int Query(int l,int r)
  87. {
  88. int mx=1e9;
  89. for(l+=N-,r+=N+;l^r^;l>>=,r>>=)
  90. {
  91. if(~l&) mx=min(mx,T[l+]);
  92. if( r&) mx=min(mx,T[r-]);
  93. }
  94. return mx;
  95. }
  96. void Add(int x,int v,int k)
  97. {
  98. ++vis[v];
  99. s[x].push(make_pair(k,v));
  100. while(!s[x].empty()&&w[s[x].top().second]!=s[x].top().first) s[x].pop();
  101. int K=s[x].size()?s[x].top().first:;Renew(dfn[x],K);
  102. }
  103. int Solve(int x,int y)
  104. {
  105. int mx=1e9;
  106. while(top[x]!=top[y])
  107. {
  108. if(dep[top[x]]<dep[top[y]]) swap(x,y);
  109. mx=min(mx,Query(dfn[top[x]],dfn[x]));
  110. x=fa[top[x]];
  111. }
  112. if(dfn[x]>dfn[y]) swap(x,y);
  113. mx=min(mx,Query(dfn[x],dfn[y]));
  114. if(x>n&&fa[x]) mx=min(mx,w[fa[x]]);
  115. return mx;
  116. }
  117. char st[];
  118. int main()
  119. {
  120. n=read();m=read();Q=read();
  121. for(int i=;i<=n;++i) w[i]=read();
  122. for(int i=;i<=m;++i) ins(read(),read());
  123. Tarjan(,);memset(T,,sizeof(T));
  124. dn=;Pre(,);Dfs(,);
  125. for(int i=;i<=n;++i)
  126. {
  127. Renew(dfn[i],w[i]);
  128. if(fa[i]) Add(fa[i],i,w[i]);
  129. }
  130. for(int i=;i<=Q;++i)
  131. {
  132. scanf("%s",st+);int x=read(),y=read();
  133. if(st[]=='A') printf("%d\n",Solve(x,y));
  134. else
  135. {
  136. w[x]=y,Renew(dfn[x],y);
  137. if(fa[x]) Add(fa[x],x,y);
  138. }
  139. }
  140. return ;
  141. }

Codeforces278E Tourists的更多相关文章

  1. 【Codefoces487E/UOJ#30】Tourists Tarjan 点双连通分量 + 树链剖分

    E. Tourists time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard inpu ...

  2. Tourists

    Tourists 时间限制: 5 Sec  内存限制: 64 MB 题目描述 In Tree City, there are n tourist attractions uniquely labele ...

  3. CF487 E. Tourists [点双连通分量 树链剖分 割点]

    E. Tourists 题意: 无向连通图 C a w: 表示 a 城市的纪念品售价变成 w. A a b: 表示有一个游客要从 a 城市到 b 城市,你要回答在所有他的旅行路径中最低售价的最低可能值 ...

  4. 【CF487E】Tourists(圆方树)

    [CF487E]Tourists(圆方树) 题面 UOJ 题解 首先我们不考虑修改,再来想想这道题目. 我们既然要求的是最小值,那么,在经过一个点双的时候,走的一定是具有较小权值的那一侧. 所以说,我 ...

  5. 每日英语:Foreign Tourists Skip Beijing

    Overseas tourists continued to shun Beijing through 2013. shun:避开,避免,回避 Amid rising pollution and a ...

  6. L192 Virgin Galactic Completes Test of Spaceship to Carry Tourists

    Virgin Galactic says its spacecraft designed to launch tourists into space completed an important te ...

  7. UOJ #30. [CF Round #278] Tourists

    UOJ #30. [CF Round #278] Tourists 题目大意 : 有一张 \(n\) 个点, \(m\) 条边的无向图,每一个点有一个点权 \(a_i\) ,你需要支持两种操作,第一种 ...

  8. [UOJ30]/[CF487E]Tourists

    [UOJ30]/[CF487E]Tourists 题目大意: 一个\(n(n\le10^5)\)个点\(m(m\le10^5)\)条边的无向图,每个点有点权.\(q(q\le10^5)\)次操作,操作 ...

  9. Tourists——圆方树

    CF487E Tourists 一般图,带修求所有简单路径代价. 简单路径,不能经过同一个点两次,那么每个V-DCC出去就不能再回来了. 所以可以圆方树,然后方点维护一下V-DCC内的最小值. 那么, ...

随机推荐

  1. 团队作业4——第一次项目冲刺(Alpha版本)11.16

    a. 提供当天站立式会议照片一张 举行站立式会议,讨论项目安排: 整理各自的任务汇报: 全分享遇到的困难一起讨论: 讨论接下来的计划: b. 每个人的工作 (有work item 的ID) 1.前两天 ...

  2. Flask 学习 十 博客文章

    提交和显示博客文章 app/models.py 文章模型 class Post(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer ...

  3. 【iOS】swift 枚举

    枚举语法 你可以用enum开始并且用大括号包含整个定义体来定义一个枚举: enum SomeEnumeration { // 在这里定义枚举 } 这里有一个例子,定义了一个包含四个方向的罗盘: enu ...

  4. bzoj千题计划288:bzoj1876: [SDOI2009]SuperGCD

    http://www.lydsy.com/JudgeOnline/problem.php?id=1876 高精压位GCD 对于  GCD(a, b)  a>b 若 a 为奇数,b 为偶数,GCD ...

  5. c 语言的基本语法

    1,c的令牌(Tokens) printf("Hello, World! \n"); 这五个令牌是: printf ( "Hello, World! \n" ) ...

  6. RxJava系列7(最佳实践)

    RxJava系列1(简介) RxJava系列2(基本概念及使用介绍) RxJava系列3(转换操作符) RxJava系列4(过滤操作符) RxJava系列5(组合操作符) RxJava系列6(从微观角 ...

  7. (Sqlyog或Navicat不友好处)SHOW ENGINE INNODB STATUS 结果为空或结果为=====================================

    因为最近在学习innodb引擎,所以就在自己的sqlyog上执行上述命令: SHOW ENGINE INNODB STATUS 结果显示如下: 换了个客户端navicat,执行如下: 最后登录到服务器 ...

  8. POJ2398【判断点在直线哪一侧+二分查找区间】

    题意:同POJ2318 #include<algorithm> #include<cstdio> #include<cstdlib> #include<cst ...

  9. C#使用Gecko实现浏览器

    Gecko就是火狐浏览器的内核啦,速度很快,兼容性比.net内置的webbrowser高到不知哪里去了. 使用Gecko首先要下载一堆依赖库,主要是Skybound.Gecko和xulrunner. ...

  10. [转][scrapy] CannotListenError: Couldn’t listen on [Errno 98] Address already in use.

    [scrapy] CannotListenError: Couldn't listen on [Errno 98] Address already in use. python  eason  1年前 ...