题面

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

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200005;
#define pb push_back inline int read(){
int x=0; char ch=getchar();
for(;!isdigit(ch);ch=getchar());
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
return x;
} vector<int> G[N];
int n,a[N],dfn[N],low[N],lt[N],k,siz[N];
int hd[N],ne[N*2],to[N*2],num=1,tot[N],dc,m,s;
ll ltw[N],ans,M,mx[N];
bool ban[N*2]; inline void add(int x,int y){
to[++num]=y,ne[num]=hd[x],hd[x]=num;
} void dfs(int x,int fa){
dfn[x]=low[x]=++dc; for(int i=hd[x];i;i=ne[i]) if(to[i]!=fa)
if(!dfn[to[i]]){
dfs(to[i],x),low[x]=min(low[x],low[to[i]]);
if(low[to[i]]>=dfn[to[i]]) ban[i]=ban[i^1]=1;
}
else low[x]=min(low[x],dfn[to[i]]);
} void B(int x){
lt[x]=k,ltw[k]+=a[x],siz[k]++;
for(int i=hd[x];i;i=ne[i]) if(!ban[i]&&!lt[to[i]]) B(to[i]);
} void dp(int x,int fa){
tot[x]=siz[x]>1;
for(int i:G[x]) if(i!=fa){
dp(i,x),tot[x]+=tot[i],mx[x]=max(mx[x],mx[i]);
} mx[x]+=ltw[x];
if(tot[x]) ans+=ltw[x];
else M=max(M,mx[x]);
} inline void solve(){
for(int i=1;i<=n;i++) if(!dfn[i]) dfs(i,i);
for(int i=1;i<=n;i++) if(!lt[i]) k++,B(i); for(int i=1;i<=n;i++)
for(int j=hd[i];j;j=ne[j]) if(lt[i]!=lt[to[j]]) G[lt[i]].pb(lt[to[j]]); dp(lt[s],0);
ans+=M;
} inline void check(){
cout<<k<<' '<<lt[s]<<endl;
for(int i=1;i<=k;i++){
cout<<i<<"'s size is"<<siz[i]<<endl;
for(int j:G[i]) cout<<j<<" ";
cout<<endl;
}
} int main(){
n=read(),m=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1,u,v;i<=m;i++) u=read(),v=read(),add(u,v),add(v,u); s=read(),solve(); cout<<ans<<endl; // check();
return 0;
}

  

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. C++ std::string 在一个字符串前插入一个字符串几种方式

    目录 1.直接使用字符串相加 2.使用insert函数 比较:通过Quick C++ Benchmarks 可得到结果 1.直接使用字符串相加 std::string a = "hello& ...

  2. Scratch与物理·天文:模拟中国嫦娥探月工程,探索月球的背面!

    北京时间2019年5月16日凌晨,国际顶级学术期刊<自然>(Nature)在线发表了一篇来自中国科学家的成果:中国的嫦娥四号月球探测器2019年1月3日在月球背面的冯卡门陨石坑(Von K ...

  3. 2019杭电多校二 F. Fantastic Magic Cube (FWT)

    大意: 给定$N^3$立方体, 每个单位立方体权值为三个坐标异或, 每次沿坐标轴切一刀, 得分为两半内权值和的乘积, 求切成$n^3$块的最大得分. 可以发现得分与切法无关, 假设每个点权值为$a_i ...

  4. 谷歌(Google)学术镜像,谷歌镜像

    谷歌(Google)学术镜像,谷歌镜像 2019-09-03 15:32:26 Hinton-wu 阅读数 6743 文章标签: 谷歌google学术镜像 更多 分类专栏: 其他   版权声明:本文为 ...

  5. 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin 矩阵快速幂

    Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face u ...

  6. hdu 5230 整数划分 dp

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5230 题意:给定n,c,l,r.求有多少种方法从1~n-1选取任意k数每个数的权重为其下标,使得这些数字之 ...

  7. .Net Core Swagger:Actions require an explicit HttpMethod binding for Swagger 2.0

    添加完Swagger包引用后运行报错:Actions require an explicit HttpMethod binding for Swagger 2.0 第一时间想到了父类控制器 没有添加 ...

  8. g++ 生成C++ .so库文件,并调用示例

    Tags: g++ C++ so library   在Linux系统下用g++命令编译C++程序.也可以生成so,a链接库   示例一 编译时链接so库 Test.h 文件内容   Main.cpp ...

  9. Spring MVC通过拦截器处理sql注入、跨站XSS攻击风险

    sql注入就是通过url或者post提交数据时候,字符串类型的参数会被别人利用传入sql语句,最终破坏数据库或者达到一些见不得人的目的. 有时候因为业务需要url中会带一些参数,比如 ?type=xx ...

  10. vue——store全局存储

    业务场景:刷新页面时,首次拉取所有配置,存储到store状态管理用于全局调用: import Vue from 'vue' import Vuex from 'vuex' import userInf ...