题面

可以发现一个边双必然是可以随意走的,所以我们就把原图求割边然后把边双缩成一个点,然后就是一个树上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. golang以服务方式运行

    golang开发的二进制程序,一般需要长期后台运行的,在linux上可以用supervisor或upstart或systemd等第三方守护进程来实现.其实golang自己也可以实现以服务的形式常驻后台 ...

  2. 【Scratch】编程?一节课就教会你!其实我们不用一个个学习如何使用代码。

    第199篇文章 老丁的课程 在很多教程里面,大家都喜欢把模块拿出来一个个讲述其功能. 这样做的好处是,可以把每个代码模块的功能讲的很清楚.但最最讨厌的问题也随之而来…… 举个例子,当你学习英语的时候, ...

  3. react封装通用tab组件

    import React, { Component } from 'react' import PropTypes from 'prop-types' import _ from 'lodash' i ...

  4. uncompyle6安装使用方法

    uncompyle6是一个原生python的跨版本反编译器和fragment反编译器,是decompyle.uncompyle.uncompyle2等的接替者. uncompyle6可将python字 ...

  5. (一)JMS简介

    一.简介 JMS即Java消息服务(Java Message Service)应用程序接口,是一个Java平台中关于面向消息中间件(MOM)的API,用于在两个应用程序之间,或分布式系统中发送消息,进 ...

  6. (五)CXF之添加拦截器

    一.需求分析 webService中的拦截器类似于servlet的Filter过滤器.一般用于调用服务前后先调用拦截器的方法. 二.案例 本章案例是基于上一章节的基础上添加拦截器的 2.1 服务端添加 ...

  7. (五)Struts之Action类基础(二)

    上一章节末((三)Struts之Action类基础(一))介绍了如何获取用户输入数据的获取.接着就是在Struts中怎么把数据响应给用户端,这就必须要求我们把数据放到作用域中,然后才能显示到用户浏览器 ...

  8. 将mdf文件copy到docker对应的目录下

    将mdf文件copy到docker对应的目录下: (<Docker-Container ID> 需要整体替换) docker cp /Users/Jay/Works/db/MyPost.m ...

  9. Windows 批处理 bat 开启 WiFi 菜单选项 设置ID PWD

    @echo off rem 设置标题 title windows 7 无线热点设置 author:humi rem 设置背景颜色 color 1E :: 设置窗口大小 mode con: cols=1 ...

  10. Flutter学习之Dart语言基础(构造函数)

    最常见的构造函数形式,即生成构造函数,创建一个类的新实例: class Point { num x, y; //Dart中int和double是num的子类 //this引用当前类对象 Point(n ...