【BZOJ1179】[Apio2009]Atm (tarjan+SPFA)
显而易见的tarjan+spfa...不解释了
const maxn=;
type
edgetype=record
toward,next:longint;
end; var
edge1,edge2:array[..maxn] of edgetype;
first1,first2,scc,stack,dfn,low,val,sum,q,d:Array[..maxn] of longint;
pd:array[..maxn] of boolean;
num,tot,n,m,cnt,top:longint; function min(x,y:longint):longint; begin if x<y then exit(x) else exit(y); end; procedure addedge(i,j:longint);
begin
inc(tot);
edge1[tot].toward:=j;
edge1[tot].next:=first1[i];
first1[i]:=tot;
end; procedure add(i,j:longint);
begin
inc(tot);
edge2[tot].toward:=j;
edge2[tot].next:=first2[i];
first2[i]:=tot;
end; procedure tarjan(v:longint);
var i,tmp,u:longint;
begin
inc(cnt); dfn[v]:=cnt; low[v]:=cnt;
inc(top); stack[top]:=v;
pd[v]:=true; i:=first1[v];
while i<> do
begin
tmp:=edge1[i].toward;
if dfn[tmp]= then
begin
tarjan(tmp);
low[v]:=min(low[v],low[tmp]);
end
else if pd[tmp] then low[v]:=min(low[v],dfn[tmp]);
i:=edge1[i].next;
end;
if low[v]=dfn[v] then
begin
inc(num);
repeat
u:=stack[top]; dec(top);
pd[u]:=false; scc[u]:=num;
inc(sum[num],val[u]);
until u=v;
end;
end; procedure spfa(s:longint);
var head,tail,i,j,tmp:longint;
begin
fillchar(d,sizeof(d),);
fillchar(pd,sizeof(pd),false);
head:=;
tail:=;
pd[scc[s]]:=true;
q[]:=scc[s];
d[scc[s]]:=sum[scc[s]];
while head<>tail do
begin
inc(head);
if head>maxn then head:=;
j:=q[head];
i:=first2[j];
while i<> do
begin
tmp:=edge2[i].toward;
if d[j]+sum[tmp]>d[tmp] then
begin
d[tmp]:=d[j]+sum[tmp];
if not pd[tmp] then
begin
inc(tail); if tail>maxn then tail:=;
q[tail]:=tmp;
pd[tmp]:=true;
end;
end;
i:=edge2[i].next;
end;
pd[j]:=false;
end;
end; procedure init;
var i,j,a,b:longint;
begin
read(n,m);
for i:= to m do
begin
readln(a,b);
addedge(a,b);
end;
for i:= to n do read(val[i]);
for i:= to n do if dfn[i]= then tarjan(i);
end; procedure solve;
var p,x,ans,s,i,j:longint;
begin
read(s,p);
tot:=;
for j:= to n do
begin
i:=first1[j];
while i<> do
begin
x:=edge1[i].toward;
if scc[x]<>scc[j] then add(scc[j],scc[x]);
i:=edge1[i].next;
end;
end;
spfa(s);
ans:=;
for i:= to p do
begin
read(x);
if d[scc[x]]>ans then ans:=d[scc[x]];
end;
writeln(ans);
end; Begin
init;
solve;
End.
【BZOJ1179】[Apio2009]Atm (tarjan+SPFA)的更多相关文章
- 【BZOJ1179】 [Apio2009]Atm tarjan缩点+SPFA
Description Input 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口 ...
- 【bzoj1179】[Apio2009]Atm Tarjan缩点+Spfa最长路
题目描述 输入 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号.接下来N行,每 ...
- 【bzoj1179】 Apio2009—Atm
www.lydsy.com/JudgeOnline/problem.php?id=1179 (题目链接) 题意 给出一张有向图,每个节点有点权.标记一些点,找出一条路径,可以重复经过一条边,使得总点权 ...
- 【bzoj1179】[Apio2009]Atm
*题目描述: *输入: 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号.接下来 ...
- bzoj 1179[Apio2009]Atm (tarjan+spfa)
题目 输入 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号.接下来N行,每行一 ...
- 【BZOJ4651】【NOI2016】网格(Tarjan,哈希)
[BZOJ4651][NOI2016]网格(Tarjan,哈希) 题面 BZOJ 洛谷 题解 首先把题目稍微变得好说一些,给定一个网格,已经删去了若干个格子 问最少删去多少个格子使得图不连通. 这题的 ...
- 【BZOJ-1179】Atm Tarjan + SPFA
1179: [Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 2407 Solved: 993[Submit][Status ...
- 【Tarjan】+【SPFA】APIO2009 Atm
一.算法介绍 tarjan——求解有向图强连通分量.这个算法在本人的一篇blog中有介绍,这里就不赘述了.贴上介绍tarjan的的blog链接:http://www.cnblogs.com/Maki- ...
- 【BZOJ 1179】[Apio2009]Atm
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] tarjan强连通缩点一下. 然后把缩点之后,每个点的钱的数累加起来. 然后从S出发 开始一边做bfs一遍做dp. 最后输出有酒吧的 ...
随机推荐
- vue项目中的函数封装
项目中一般都会有fun.js这类的文件,里面有各种的如转换时间格式的,处理转换的等等函数方法. 其实经常用到的去获取基本数据的接口也可以封装成一个方法,方便复用. 如上面所标,获取列表数据之前需要先获 ...
- Linux添加swap分区
swap分区的作用为当系统的物理内存不够用的时候,就需要将物理内存中的一部分空间释放出来,以供当前运行的程序使用,那些被释放的空间可能来自一些很长时间没有什么操作的程序,这些被释放的空间被临时保存到S ...
- ElasticSearch High Level REST API【7】聚合
获取平均值聚合示例,最大值.最小值.求和类似 public void aggregation(){ RestHighLevelClient client = elasticClient.getRest ...
- 给树莓派Raspbian stretch版本修改软件源
树莓派最新的系统版本是stretch,试了阿里和网易的软件源都不行,最后试了清华的可以 deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbia ...
- 再次写给VC++ Windows开发者
距离我的上一篇文章--写给VC++ Windows开发的初学者已经4年多时间过去了,感慨于时光如梭之余,更感慨于这么多年来(从1998年我初学VC 算起吧)到如今其实我仍然还只是个初学者而已.看看之前 ...
- MyCat实现数据库与数据库之间的读写分离
一.Mycat的安装准备: 1.jdk:要求jdk必须是1.7及以上版本 2.Mysql:推荐mysql是5.5以上版本 3.Mycat: Mycat的官方网站: http://www.mycat.o ...
- 解决SecureCRT远程Linux遇到文件不能直接往CRT里直接拖入的问题
不能拖入到CRT的第一个原因可能是Options-->Global Options-->Terminal中的Mouse下的Copy on select没有勾选.当发现自己勾选了也不能往里面 ...
- 34-Cookie-based认证实现
新建MVC项目,然后用VSCode打开 dotnet new mvc --name MvcCookieAuthSample 在Controllers文件夹下新建AdminController.cs u ...
- perl实现监控linux
1.使用root用户telnet进入linux系统 2.修改DNS以下两种方法 A.通过setup命令配置dns B.通过在/etc目录下创建resolv.conf文件 3.查看DNS是否配置成功 [ ...
- 流量操控之SSH隧道与端口转发
目 录 第1章 概述... 3 1.1. 实现命令... 3 1.2. SSH隧道类型... 3 第2章 SSH隧道... ...