题面

可以发现一个边双必然是可以随意走的,所以我们就把原图求割边然后把边双缩成一个点,然后就是一个树上dp了。

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const int N=200005;
  5. #define pb push_back
  6.  
  7. inline int read(){
  8. int x=0; char ch=getchar();
  9. for(;!isdigit(ch);ch=getchar());
  10. for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
  11. return x;
  12. }
  13.  
  14. vector<int> G[N];
  15. int n,a[N],dfn[N],low[N],lt[N],k,siz[N];
  16. int hd[N],ne[N*2],to[N*2],num=1,tot[N],dc,m,s;
  17. ll ltw[N],ans,M,mx[N];
  18. bool ban[N*2];
  19.  
  20. inline void add(int x,int y){
  21. to[++num]=y,ne[num]=hd[x],hd[x]=num;
  22. }
  23.  
  24. void dfs(int x,int fa){
  25. dfn[x]=low[x]=++dc;
  26.  
  27. for(int i=hd[x];i;i=ne[i]) if(to[i]!=fa)
  28. if(!dfn[to[i]]){
  29. dfs(to[i],x),low[x]=min(low[x],low[to[i]]);
  30. if(low[to[i]]>=dfn[to[i]]) ban[i]=ban[i^1]=1;
  31. }
  32. else low[x]=min(low[x],dfn[to[i]]);
  33. }
  34.  
  35. void B(int x){
  36. lt[x]=k,ltw[k]+=a[x],siz[k]++;
  37. for(int i=hd[x];i;i=ne[i]) if(!ban[i]&&!lt[to[i]]) B(to[i]);
  38. }
  39.  
  40. void dp(int x,int fa){
  41. tot[x]=siz[x]>1;
  42. for(int i:G[x]) if(i!=fa){
  43. dp(i,x),tot[x]+=tot[i],mx[x]=max(mx[x],mx[i]);
  44. }
  45.  
  46. mx[x]+=ltw[x];
  47. if(tot[x]) ans+=ltw[x];
  48. else M=max(M,mx[x]);
  49. }
  50.  
  51. inline void solve(){
  52. for(int i=1;i<=n;i++) if(!dfn[i]) dfs(i,i);
  53. for(int i=1;i<=n;i++) if(!lt[i]) k++,B(i);
  54.  
  55. for(int i=1;i<=n;i++)
  56. for(int j=hd[i];j;j=ne[j]) if(lt[i]!=lt[to[j]]) G[lt[i]].pb(lt[to[j]]);
  57.  
  58. dp(lt[s],0);
  59. ans+=M;
  60. }
  61.  
  62. inline void check(){
  63. cout<<k<<' '<<lt[s]<<endl;
  64. for(int i=1;i<=k;i++){
  65. cout<<i<<"'s size is"<<siz[i]<<endl;
  66. for(int j:G[i]) cout<<j<<" ";
  67. cout<<endl;
  68. }
  69. }
  70.  
  71. int main(){
  72. n=read(),m=read();
  73. for(int i=1;i<=n;i++) a[i]=read();
  74. for(int i=1,u,v;i<=m;i++) u=read(),v=read(),add(u,v),add(v,u);
  75.  
  76. s=read(),solve();
  77.  
  78. cout<<ans<<endl;
  79.  
  80. // check();
  81. return 0;
  82. }

  

Codeforces 1220 E Tourism的更多相关文章

  1. Codeforces Round #586 (Div. 1 + Div. 2) E. Tourism

    链接: https://codeforces.com/contest/1220/problem/E 题意: Alex decided to go on a touristic trip over th ...

  2. Codeforces 1220E. Tourism

    传送门 这是一道英语题,首先要读懂题目: $\text{Alex believes that his trip will be interesting only if he will not use ...

  3. Codeforces Round #586 (Div. 1 + Div. 2) D. Alex and Julian

    链接: https://codeforces.com/contest/1220/problem/D 题意: Boy Dima gave Julian a birthday present - set ...

  4. Codeforces Round #586 (Div. 1 + Div. 2) C. Substring Game in the Lesson

    链接: https://codeforces.com/contest/1220/problem/C 题意: Mike and Ann are sitting in the classroom. The ...

  5. Codeforces Round #586 (Div. 1 + Div. 2) B. Multiplication Table

    链接: https://codeforces.com/contest/1220/problem/B 题意: Sasha grew up and went to first grade. To cele ...

  6. Codeforces Round #586 (Div. 1 + Div. 2) A. Cards

    链接: https://codeforces.com/contest/1220/problem/A 题意: When Serezha was three years old, he was given ...

  7. Codeforces 杂题集 2.0

      记录一些没有写在其他随笔中的 Codeforces 杂题, 以 Problemset 题号排序   1326D2 - Prefix-Suffix Palindrome (Hard version) ...

  8. Codeforces Round #635 (Div. 2) 题解

    渭城朝雨浥轻尘,客舍青青柳色新. 劝君更尽一杯酒,西出阳关无故人.--王维 A. Ichihime and Triangle 网址:https://codeforces.com/contest/133 ...

  9. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

随机推荐

  1. PHP正则 正向预查&反向预查

    了解正向预查&反向预查前,我们先要知道正则的2个函数:preg_match_all . preg_replace preg_match_all 可以看文章:点击查看 preg_replace ...

  2. Qt中容器类应该如何存储对象(最好使用对象指针类型,如:QList<TestObj*>,而不要使用 QList<TestObj> 这样的定义,建议采用 智能指针QSharedPointer)

    Qt提供了丰富的容器类型,如:QList.QVector.QMap等等.详细的使用方法可以参考官方文档,网上也有很多示例文章,不过大部分文章的举例都是使用基础类型:如int.QString等.如果我们 ...

  3. 2019杭电多校二 L. Longest Subarray (线段树)

    大意: 给定序列$a$, 元素范围$[1,C]$, 求一个最长子序列, 满足每个元素要么不出现, 要么出现次数$\le K$. 枚举右端点, 考虑左端点合法的位置. 显然一定是$C$种颜色合法位置的交 ...

  4. (三)mybatis之通过接口加载映射配置文件

    1.1  需求 通过(二)在全局配置文件 mybatis-configuration.xml 通过 <mappers> 标签来加载映射文件,那么如果我们项目足够大,有很多映射文件呢,难道我 ...

  5. eclipse怎样修改同名包(package)的显示样式、格式

    打开我们的项目,可以看到左侧的package看上去特别多,没有层级. 点击Package Explorer右上角的箭头图标. 可以看到“Flat(扁平)”,“Hierarchical(分层)”两个选项 ...

  6. Spring Boot 项目集成 Alibaba Druid

    Druid 是一个非常好用的数据库连接池,但是他的好并不止体现在作为一个连接池加快数据访问性能上和连接管理上,他带有一个强大的监控工具:Druid Monitor.不仅可以监控数据源和慢查询,还可以监 ...

  7. 验证 vector = 是深拷贝还是浅拷贝

    #include <vector> using namespace std; int main() { int w=1920; int h = 1080; vector<int> ...

  8. nodejs入门API之path模块

    Path模块在各个系统上的差异 Path模块API解析 一.Path模块在各个系统上的差异 path模块提供用于处理文件路径和目录路径的使用工具. let path = require('path') ...

  9. 操作系统 (OS)

    1. 操作系统(Operation System,OS) 操作系统作为接口的示意图 没有安装操作系统的计算机,通常被称为 裸机 如果想在 裸机 上运行自己所编写的程序,就必须用机器语言书写程序 如果计 ...

  10. openpyxl 设置单元格颜色

    在处理excel数据格式的时候,需要对特定单元格进行颜色标注,方便相关人员查看 醒目 # -*- coding: utf-8 -*- from openpyxl import load_workboo ...