题面

可以发现一个边双必然是可以随意走的,所以我们就把原图求割边然后把边双缩成一个点,然后就是一个树上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. MVC——三层架构笔记、1

    三层架构MVC笔记1. DAL——数据访问层:(专门与数据库交互,增删查改的方法都在这:需引用MODEL层) BLL——业务逻辑层:(页面与数据库之间的桥梁:需引用DAL.MODEL层) MODEL— ...

  2. NeurIPS 2018 中的贝叶斯研究

    NeurIPS 2018 中的贝叶斯研究 WBLUE 2018年12月21日   雷锋网 AI 科技评论按:神经信息处理系统大会(NeurIPS)是人工智能领域最知名的学术会议之一,NeurIPS 2 ...

  3. 一个炒鸡好用的pdf阅读器

    下载地址:https://www.sumatrapdfreader.org/free-pdf-reader.html 一个关系很好的同事推荐的pdf阅读器  之前用的感觉不错  每次都记不住  自己收 ...

  4. 验证码识别的免费 OCR

    在做接口自动化以及爬虫的过程中,验证码一般是个很烦的存在,其实大厂们已经做好了一些 OCR 供使用,这里介绍一下百度 OCR 的使用方法. 注册并生成应用 1.注册一个百度智能云账号:http://a ...

  5. Nopcommerce4.2解析——安装

    Nopcommerce是一个DotNet领域异常凶残的一个开源电商系统,最先版本4.2,下面我们会逐步分析他的各个模块,为我们的二次开发做准备,应该会写一个系列. 首次运行nop页面会自动跳转到安装页 ...

  6. Python练习_初识数据类型_day3

    题目 1. 作业 1,有变量name = "aleX leNb" 完成如下操作: 1) 移除 name 变量对应的值两边的空格,并输出处理结果 2) 移除name变量左边的&quo ...

  7. linux内核过高导致vm打开出错修复脚本

    #!/bin/bashVMWARE_VERSION=workstation-15.1.0TMP_FOLDER=/tmp/patch-vmwarerm -fdr $TMP_FOLDERmkdir -p ...

  8. 简单SQL注入试探、二

    DVWA——简单SQL注入小记 今天我们来记录简单的盲注过程 简单的SQL injection(blind) Level:low 登陆后选择SQL Injection(Blind) 能看到这样的界面 ...

  9. 第三章 Django之动态网页基础(1)

    前一章中,我们解释了如何建立一个 Django 项目并启动 Django 开发服务器.当然,那个网站实际并没有干什么有用的事情,它所做的只是显示 It worked!消息.让我们来做些改变.本章将介绍 ...

  10. 一个基于Scrapy框架的pixiv爬虫

    源码 https://github.com/vicety/Pixiv-Crawler,功能什么的都在这里介绍了 说几个重要的部分吧 登录部分 困扰我最久的部分,网上找的其他pixiv爬虫的登录方式大多 ...