Codeforces 1220 E Tourism
可以发现一个边双必然是可以随意走的,所以我们就把原图求割边然后把边双缩成一个点,然后就是一个树上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的更多相关文章
- 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 ...
- Codeforces 1220E. Tourism
传送门 这是一道英语题,首先要读懂题目: $\text{Alex believes that his trip will be interesting only if he will not use ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces 杂题集 2.0
记录一些没有写在其他随笔中的 Codeforces 杂题, 以 Problemset 题号排序 1326D2 - Prefix-Suffix Palindrome (Hard version) ...
- Codeforces Round #635 (Div. 2) 题解
渭城朝雨浥轻尘,客舍青青柳色新. 劝君更尽一杯酒,西出阳关无故人.--王维 A. Ichihime and Triangle 网址:https://codeforces.com/contest/133 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- PHP正则 正向预查&反向预查
了解正向预查&反向预查前,我们先要知道正则的2个函数:preg_match_all . preg_replace preg_match_all 可以看文章:点击查看 preg_replace ...
- Qt中容器类应该如何存储对象(最好使用对象指针类型,如:QList<TestObj*>,而不要使用 QList<TestObj> 这样的定义,建议采用 智能指针QSharedPointer)
Qt提供了丰富的容器类型,如:QList.QVector.QMap等等.详细的使用方法可以参考官方文档,网上也有很多示例文章,不过大部分文章的举例都是使用基础类型:如int.QString等.如果我们 ...
- 2019杭电多校二 L. Longest Subarray (线段树)
大意: 给定序列$a$, 元素范围$[1,C]$, 求一个最长子序列, 满足每个元素要么不出现, 要么出现次数$\le K$. 枚举右端点, 考虑左端点合法的位置. 显然一定是$C$种颜色合法位置的交 ...
- (三)mybatis之通过接口加载映射配置文件
1.1 需求 通过(二)在全局配置文件 mybatis-configuration.xml 通过 <mappers> 标签来加载映射文件,那么如果我们项目足够大,有很多映射文件呢,难道我 ...
- eclipse怎样修改同名包(package)的显示样式、格式
打开我们的项目,可以看到左侧的package看上去特别多,没有层级. 点击Package Explorer右上角的箭头图标. 可以看到“Flat(扁平)”,“Hierarchical(分层)”两个选项 ...
- Spring Boot 项目集成 Alibaba Druid
Druid 是一个非常好用的数据库连接池,但是他的好并不止体现在作为一个连接池加快数据访问性能上和连接管理上,他带有一个强大的监控工具:Druid Monitor.不仅可以监控数据源和慢查询,还可以监 ...
- 验证 vector = 是深拷贝还是浅拷贝
#include <vector> using namespace std; int main() { int w=1920; int h = 1080; vector<int> ...
- nodejs入门API之path模块
Path模块在各个系统上的差异 Path模块API解析 一.Path模块在各个系统上的差异 path模块提供用于处理文件路径和目录路径的使用工具. let path = require('path') ...
- 操作系统 (OS)
1. 操作系统(Operation System,OS) 操作系统作为接口的示意图 没有安装操作系统的计算机,通常被称为 裸机 如果想在 裸机 上运行自己所编写的程序,就必须用机器语言书写程序 如果计 ...
- openpyxl 设置单元格颜色
在处理excel数据格式的时候,需要对特定单元格进行颜色标注,方便相关人员查看 醒目 # -*- coding: utf-8 -*- from openpyxl import load_workboo ...