Luogu P3627 抢掠计划
题目传送门
\(Tarjan\)缩点+SPFA最长路
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct zzz{
int f,t,nex;
}e[500010]; int head[500010],tot;
void add(int x,int y){
e[++tot].f=x;
e[tot].t=y;
e[tot].nex=head[x];
head[x]=tot;
}
int dfn[500010],low[500010],deth,s[500010],top,col,belong[500010];
bool vis[500010];
void tarjan(int f){
dfn[f]=low[f]=++deth;
s[++top]=f; vis[f]=1;
for(int i=head[f];i;i=e[i].nex){
int to=e[i].t;
if(!dfn[to]){
tarjan(to); low[f]=min(low[f],low[to]);
}
else
if(vis[to]) low[f]=min(low[f],dfn[to]);
}
if(dfn[f]==low[f]){
col++;
int k=0;
do{
k=s[top--];
vis[k]=0;
belong[k]=col;
}while(k!=f);
}
}
int read(){
int k=0; char c=getchar();
for(;c<'0'||c>'9';) c=getchar();
for(;c>='0'&&c<='9';c=getchar())
k=(k<<3)+(k<<1)+c-48;
return k;
}
int atm[500010]; bool cof[500010];
int q[500010<<2],dis[500010]; int h=1,tail;
int main(){
int n=read(),m=read();
for(int i=1;i<=m;i++){
int x=read(),y=read();
add(x,y);
}
for(int i=1;i<=n;i++)
if(!dfn[i]) tarjan(i);
for(int i=1;i<=n;i++)
atm[belong[i]]+=read();
int s=read(),cnt=read();
for(int i=1;i<=cnt;i++)
cof[belong[read()]]=1;
memset(head,0,sizeof(head)); tot=0;
for(int i=1;i<=m;i++){
int x=belong[e[i].f],y=belong[e[i].t];
if(x!=y) add(x,y);
}
memset(vis,0,sizeof(vis));
q[++tail]=belong[s]; dis[belong[s]]=atm[belong[s]];
vis[belong[s]]=1;
while(h<=tail){
int k=q[h]; h++; vis[k]=0;
for(int i=head[k];i;i=e[i].nex){
int to=e[i].t;
if(dis[k]+atm[to]>dis[to]){
dis[to]=atm[to]+dis[k];
if(!vis[to])
q[++tail]=to, vis[to]=1;
}
}
}
int ans=0;
for(int i=1;i<=col;i++)
if(cof[i]) ans=max(ans,dis[i]);
cout<<ans;
return 0;
}
Luogu P3627 抢掠计划的更多相关文章
- 【Luogu】P3627抢掠计划(缩点最短路)
题目链接在此 有环当然一定尽量走环,这是搞缩点的人都知道的常识. 建了新图之后搞点权SPFA跑最长路.枚举每个酒吧选择最大值. 发现我的博客写的越来越水了 #include<cstdio> ...
- 洛谷 P3627 【抢掠计划】
题库:洛谷 题号:3627 题目:抢掠计划 link:https://www.luogu.org/problem/P3627 思路 : 这道题是一道Tarjan + 最长路的题.首先,我们用Tarja ...
- 题解 P3627 【[APIO2009]抢掠计划】
咕了四个小时整整一晚上 P3627 [APIO2009] 抢掠计划(https://www.luogu.org/problemnew/show/P3627) 不难看出答案即为该有向图的最长链长度(允许 ...
- P3627 [APIO2009]抢掠计划
P3627 [APIO2009]抢掠计划 Tarjan缩点+最短(最长)路 显然的缩点...... 在缩点时,顺便维护每个强连通分量的总权值 缩完点按照惯例建个新图 然后跑一遍spfa最长路,枚举每个 ...
- 【洛谷P3627】[APIO2009]抢掠计划
抢掠计划 题目链接 比较水的缩点模板题,Tarjan缩点,重新建图,记录联通块的钱数.是否有酒吧 DAG上记忆化搜索即可 #include<iostream> #include<cs ...
- APIO2009 抢掠计划 Tarjan DAG-DP
APIO2009 抢掠计划 Tarjan spfa/DAG-DP 题面 一道\(Tarjan\)缩点水题.因为可以反复经过节点,所以把一个联通快中的所有路口看做一个整体,缩点后直接跑\(spfa\)或 ...
- [APIO2009]抢掠计划(Tarjan,SPFA)
[APIO2009]抢掠计划 题目描述 Siruseri 城中的道路都是单向的.不同的道路由路口连接.按照法律的规定, 在每个路口都设立了一个 Siruseri 银行的 ATM 取款机.令人奇怪的是, ...
- 【luogu P3627 [APIO2009]抢掠计划】 题解
题目链接:https://www.luogu.org/problemnew/show/P3627 把点权转化到边权上去. #include <stack> #include <que ...
- 洛谷 P3627 [APIO2009]抢掠计划 Tarjan缩点+Spfa求最长路
题目地址:https://www.luogu.com.cn/problem/P3627 第一次寒假训练的结测题,思路本身不难,但对于我这个码力蒟蒻来说实现难度不小-考试时肛了将近两个半小时才刚肛出来. ...
随机推荐
- HDU2896【AC自动机-模板】
思路: 因为不同病毒特征码不会相同. AC自动机,然后对于每一个输出即可. 注意:以上字符串中字符都是ASCII码可见字符(不包括回车);G++ MLE. //#include <bits/st ...
- HDU5971【瞎搞】
题意:略(忙着准备文化课...明天期中考啊.... 思路: 正解就是染色,2-sat搞: AC代码(虽然是错误的...数据水(过踏马的也行啊,起码打脸他啊!) 4 3 1 0 1 2 2 3 3 4 ...
- Modulation of Lipid Metabolism by Celastrol (文献分享一组-赵倩倩)
文献名:Modulation of Lipid Metabolism by Celastrol (雷公藤红素对脂质代谢调节作用的研究) 期刊名:Journal of Proteome Research ...
- assembly x86(nasm)选择排序
有一个首地址为NUM的N字无序无符号整数数组,编制程序采用选择排序法使该数组中的数按照从小到大的次序排序输出. 选择排序: data segment message db 'This is a pro ...
- hard(2018.10.18)
题意:给你一棵\(n\)个节点的树,\(q\)个询问,每次询问读入\(u,v,k,op\),需要满足树上有\(k\)对点的简单路径交都等于\(u,v\)之间的简单路径,\(op=1\)表示\(k\)对 ...
- 在Mac上安装Ubuntu14.04虚拟机
1.在macOS High Sierras上安装VMware for mac 下载地址:VMware Fusion 8.5.1 https://pan.baidu.com/s/1skQ1OyL 2. ...
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) B
Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. ...
- yii2 加载静态资源
1.在 assets/AppAsset 里定义方法 <?php /** * @link http://www.yiiframework.com/ * @copyright Copyright ( ...
- Wordpress 之 Rewrite Rules
----------------------------------------------------------------- 场景描述: 自定义wp主题中,添加了个关于页面(about.php) ...
- Vue简单项目(页面跳转,参数传递)
一.页面跳转 1.和上篇文章一样的建文件的步骤 2.建立成功之后,在src文件夹下面添加新的文件夹pages 3.在pages里面添加新的文件Home.Vue和Detail.Vue 4.设Home.V ...