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

6 7
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

47

HINT

50%的输入保证N, M<=3000。所有的输入保证N, M<=500000。每个ATM机中可取的钱数为一个非负整数且不超过4000。输入数据保证你可以从市中心沿着Siruseri的单向的道路到达其中的至少一个酒吧。

Source

 题解:其实就是个tarjan求出强连通分量,缩个点,然后直接BFS扫一遍就完事了。。。但是问题来了,莫名其妙的WA了好多次,弄到数据才发现原来tarjan爆栈了(HansBug:TT)。。。后来加了个{$M 1000000000,0,maxlongint}就没事啦么么哒(再次对C/C++党的无限栈空间表示严重鄙视TT)
 /**************************************************************
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的更多相关文章

  1. BZOJ 1179: [Apio2009]Atm( tarjan + 最短路 )

    对于一个强连通分量, 一定是整个走或者不走, 所以tarjan缩点然后跑dijkstra. ------------------------------------------------------ ...

  2. 缩点+spfa最长路【bzoj】 1179: [Apio2009]Atm

    [bzoj] 1179: [Apio2009]Atm Description Siruseri 城中的道路都是单向的.不同的道路由路口连接.按照法律的规定, 在每个路口都设立了一个 Siruseri ...

  3. bzoj 1179 [Apio2009]Atm 缩点+最短路

    [Apio2009]Atm Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 4290  Solved: 1893[Submit][Status][Dis ...

  4. 【BZOJ】1179: [Apio2009]Atm(tarjan+spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1179 缩点建图... #include <cstdio> #include <cs ...

  5. bzoj 1179[Apio2009]Atm (tarjan+spfa)

    题目 输入 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号.接下来N行,每行一 ...

  6. BZOJ 1179 [Apio2009]Atm(强连通分量)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1179 [题目大意] 给出一张有向带环点权图,给出一些终点,在路径中同一个点的点权只能累 ...

  7. bzoj 1179: [Apio2009]Atm

    Description Input 第 一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路 的起点和终点的 ...

  8. bzoj 1179 [Apio2009]Atm——SCC缩点+spfa

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1179 显然SCC缩点. 然后准备倒着拓扑序推到st,结果WA. 听TJ说dj求最长路会发生不 ...

  9. bzoj 1179: [Apio2009]Atm【tarjan+spfa】

    明明优化了spfa还是好慢-- 因为只能取一次值,所以先tarjan缩点,把一个scc的点权和加起来作为新点的点权,然后建立新图.在新图上跑spfa最长路,最后把酒吧点的dis取个max就是答案. # ...

随机推荐

  1. july教你如何迅速秒杀掉:99%的海量数据处理面试题

    作者:July出处:结构之法算法之道blog 以下是原博客链接网址 http://blog.csdn.net/v_july_v/article/details/7382693 微软面试100题系列 h ...

  2. jQuery基本过滤选择器

    jQuery基本过滤选择器: <h1>this is h1</h1> <div id="p1"> <h2>this is h2< ...

  3. Java中正则表达式的几种用法

    多数内容转载自:http://www.jb51.net/tools/regex.htm ,有改动 用到了java.util.regex包: 1. 验证 Pattern pattern = Patter ...

  4. C#中 Thread,Task,Async/Await,IAsyncResult 的那些事儿!

    说起异步,Thread,Task,async/await,IAsyncResult 这些东西肯定是绕不开的,今天就来依次聊聊他们 1.线程(Thread) 多线程的意义在于一个应用程序中,有多个执行部 ...

  5. eclipse中的Java项目导出成为一个可以直接双击运行的jar文件

    1. 选择要到处JAR文件的工程,右键选择“Export” 2. 选择“Java-->Runnable JAR file”,点击“Next”: 3. 在“Launch configuration ...

  6. [Scoi2010]游戏

    游戏 Time Limit:5000MS     Memory Limit:165888KB     64bit IO Format:%lld & %llu Submit Status Pra ...

  7. 微信LazyMan笔试题的深入解析和实现

    一.题目介绍  以下是我copy自网上的面试题原文: 实现一个LazyMan,可以按照以下方式调用: LazyMan("Hank")输出: Hi! This is Hank!   ...

  8. We Chall-Prime Factory-Writeup

    MarkdownPad Document html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,ab ...

  9. (@WhiteTaken)设计模式学习——工厂方法模式

    这个工厂方法模式,是简单工厂的延伸,不同点在于,将某个具体的类继续细分,将核心部分抽象成一个接口.而简单工厂,把核心写在了一个类上,不利于拓展. 举个例子,简单工厂中有苹果类,香蕉类,我们创建了一个F ...

  10. webapi 发布接口报405错误(angularjs2.0)

    参考链接:http://www.cnblogs.com/shenbin/p/5680976.html web访问接口报405错误,以前的jQuery访问方式访问接口没有问题. 但是换成angularj ...