1179: [Apio2009]Atm
1179: [Apio2009]Atm
Time Limit: 15 Sec Memory Limit: 162 MB
Submit: 1629 Solved: 615
[Submit][Status]
Description

Input
第一行包含两个整数N、M。N表示路口的个数,M表示道路条数。接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号。接下来N行,每行一个整数,按顺序表示每个路口处的ATM机中的钱数。接下来一行包含两个整数S、P,S表示市中心的编号,也就是出发的路口。P表示酒吧数目。接下来的一行中有P个整数,表示P个有酒吧的路口的编号
Output
输出一个整数,表示Banditji从市中心开始到某个酒吧结束所能抢劫的最多的现金总数。
Sample Input
1 2
2 3
3 5
2 4
4 1
2 6
6 5
10
12
8
16
1 5
1 4
4
3
5
6
Sample Output
HINT
50%的输入保证N, M<=3000。所有的输入保证N, M<=500000。每个ATM机中可取的钱数为一个非负整数且不超过4000。输入数据保证你可以从市中心沿着Siruseri的单向的道路到达其中的至少一个酒吧。
Source
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ {$M 1000000000,0,maxlongint}
type
point=^node;
node=record
g:longint;
next:point;
end;
art=array[..] of point;
var
i,j,k,l,m,n,h,t,ans,x,y:longint;
a,d:art;
p:point;
ss,s:array[..] of boolean;
low,dfn,f,b,c,e,g:array[..] of longint;
function min(x,y:longint):longint;inline;
begin
if x<y then min:=x else min:=y;
end;
function max(x,y:longint):longint;inline;
begin
if x>y then max:=x else max:=y;
end;
procedure add(var a:art;x,y:longint);INLINE;
var p:point;
begin
new(p);
p^.g:=y;
p^.next:=a[x];
a[x]:=p;
end;
procedure tarjan(x:longint);inline;
var i,j,k:longint;p:point;
begin
inc(h);low[x]:=h;dfn[x]:=h;
inc(t);f[t]:=x;ss[x]:=true;s[x]:=true;
p:=a[x];
while p<>nil do
begin
if s[p^.g]=false then
begin
tarjan(p^.g);
low[x]:=min(low[x],low[p^.g]);
end
else if ss[p^.g] then low[x]:=min(low[x],dfn[p^.g]);
p:=p^.next;
end;
if dfn[x]=low[x] then
begin
inc(ans);
while f[t+]<>x do
begin
ss[f[t]]:=false;
b[f[t]]:=ans;
dec(t);
end;
end;
end;
procedure search(x:longint);inline;
var
p:point;
f,r,i,j,k:longint;
b:array[..] of longint;
begin
f:=;r:=;
b[]:=x;
while f<r do
begin
p:=a[b[f]];
while p<>nil do
begin
if (e[b[f]]+c[p^.g])>e[p^.g] then
begin
e[p^.g]:=e[b[f]]+c[p^.g];
b[r]:=p^.g;
inc(r);
end;
p:=p^.next;
end;
inc(f);
end;
end;
begin
read(n,m);
for i:= to n do a[i]:=nil;
for i:= to m do
begin
read(j,k);
add(a,j,k);
end;
fillchar(s,sizeof(s),false);
fillchar(ss,sizeof(ss),false);
fillchar(f,sizeof(f),);
fillchar(low,sizeof(low),);
fillchar(dfn,sizeof(dfn),);
fillchar(b,sizeof(b),);
fillchar(c,sizeof(c),); for i:= to n do
read(g[i]);
read(x,m);
ans:=;h:=;t:=;
tarjan(x);
x:=b[x];
for i:= to n do d[i]:=a[i];
for i:= to n do a[i]:=nil;
for i:= to n do c[b[i]]:=c[b[i]]+g[i];
fillchar(s,sizeof(s),false);
for i:= to n do
begin
p:=d[i];
while p<> nil do
begin
if b[i]<>b[p^.g] then add(a,b[i],b[p^.g]);
p:=p^.next;
end;
end; fillchar(e,sizeof(e),);
e[x]:=c[x];
search(x);k:=;
for i:= to m do
begin
read(j);
k:=max(k,e[b[j]]);
end;
writeln(k);
readln;
readln;
end.
1179: [Apio2009]Atm的更多相关文章
- BZOJ 1179: [Apio2009]Atm( tarjan + 最短路 )
对于一个强连通分量, 一定是整个走或者不走, 所以tarjan缩点然后跑dijkstra. ------------------------------------------------------ ...
- 缩点+spfa最长路【bzoj】 1179: [Apio2009]Atm
[bzoj] 1179: [Apio2009]Atm Description Siruseri 城中的道路都是单向的.不同的道路由路口连接.按照法律的规定, 在每个路口都设立了一个 Siruseri ...
- bzoj 1179 [Apio2009]Atm 缩点+最短路
[Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 4290 Solved: 1893[Submit][Status][Dis ...
- 【BZOJ】1179: [Apio2009]Atm(tarjan+spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=1179 缩点建图... #include <cstdio> #include <cs ...
- bzoj 1179[Apio2009]Atm (tarjan+spfa)
题目 输入 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号.接下来N行,每行一 ...
- BZOJ 1179 [Apio2009]Atm(强连通分量)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1179 [题目大意] 给出一张有向带环点权图,给出一些终点,在路径中同一个点的点权只能累 ...
- bzoj 1179: [Apio2009]Atm
Description Input 第 一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路 的起点和终点的 ...
- bzoj 1179 [Apio2009]Atm——SCC缩点+spfa
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1179 显然SCC缩点. 然后准备倒着拓扑序推到st,结果WA. 听TJ说dj求最长路会发生不 ...
- bzoj 1179: [Apio2009]Atm【tarjan+spfa】
明明优化了spfa还是好慢-- 因为只能取一次值,所以先tarjan缩点,把一个scc的点权和加起来作为新点的点权,然后建立新图.在新图上跑spfa最长路,最后把酒吧点的dis取个max就是答案. # ...
随机推荐
- Express4.x安装
1.首先肯定是要安装Node.JS npm install -g expressnpm install -g express-generator 运行express -V输出 4.9.0 2.创建一个 ...
- MyBatis与Spring集成
beans.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
- js实现数组去重并且显示重复的元素和索引值
var arr=["a","b","c","d","c","b","d ...
- MongoDB与Redis的比较
MongoDB和Redis都是NoSQL,采用结构型数据存储.二者在使用场景中,存在一定的区别,这也主要由于二者在内存映射的处理过程,持久化的处理方法不同. MongoDB建议集群部署,更多的考虑到集 ...
- EntityFramework Core并发导致显示插入主键问题
前言 之前讨论过EntityFramework Core中并发问题,按照官网所给并发冲突解决方案以为没有什么问题,但是在做单元测试时发现too young,too siimple,下面我们一起来看看. ...
- JS 与 OC
做项目需要从网页点击跳转到app的一个页面上,并且需要获取参数. 当时后台给写的参数是这样的.自己打开浏览器看的源码 JavaScript:window.location.href= 这句话在js ...
- 构建自动化前端样式回归测试——BackstopJS篇
在使用scss和less开发的时候,遇到过一件很有趣的事,因为网站需要支持响应式,就开了一个响应式样式框架,简单的几百行scss代码,居然生成了近100KB的css代码,因此决定重构这个样式库.而重构 ...
- executssql 函数的每一句代码的意思
Public Function Executesql(ByVal sql As String, Msgstring As String) As ADODB.Recordset Dim cnn As A ...
- ABP框架 - 嵌入资源
文档目录 本节内容: 简介 创建嵌入文件 xproj/project.json 格式 csproj 格式 添加到嵌入式资源管理器 使用嵌入式视图 使用嵌入式资源 ASP.NET Core 配置 忽略文 ...
- 走进javascript——DOM事件
DOM事件模型 在0级DOM事件模型中,它只是简单的执行你为它绑定的事件,比如你为某个元素添加了一个onclick事件,当事件触发时,它只是去调用我们绑定的那个方法,不再做其他的操作. 在2级DOM事 ...