P1179: [Apio2009]Atm
缩点+spfa最短路,因为最终不可能有环,所以直接spfa。
const maxe=;
type
node=record
f,t:longint;
end;
var n,m,s,i,j,ans,cnt,num,u,x,dgr:longint;
h,he,dfn,low,q,d,v,va,bl:array[..maxe] of longint;
b,bi:array[..maxe] of node;
f:array[..maxe*] of longint;
p:array[..maxe] of boolean;
function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end;
procedure insert(u,v:longint);
begin
with bi[i] do
begin
f:=he[u];
t:=v;
end;
he[u]:=i;
end;
procedure reinsert(u,v:longint);
begin
inc(cnt);
with b[cnt] do
begin
f:=h[u];
t:=v;
end;
h[u]:=cnt;
end;
procedure readd;
var i,e,v:longint;
begin
cnt:=;
for i:= to n do
begin
e:=he[i];
while e<> do
begin
v:=bi[e].t;
if bl[i]<>bl[v] then reinsert(bl[i],bl[v]);
e:=bi[e].f;
end;
end;
end;
procedure tarjan(x:longint);
var e,t,j:longint;
begin
inc(dgr); inc(num);
p[x]:=true; f[num]:=x; dfn[x]:=dgr; low[x]:=dgr;
e:=he[x];
while e<> do
begin
t:=bi[e].t;
if dfn[t]= then
begin
tarjan(t);
if low[x]>low[t] then low[x]:=low[t];
end
else if (p[t]) and (dfn[t]<low[x]) then low[x]:=dfn[t];
e:=bi[e].f;
end;
if dfn[x]=low[x] then
begin
j:=; inc(cnt);
while j<>x do
begin
j:=f[num];
dec(num);
p[j]:=false;
bl[j]:=cnt;
//writeln(j,' ',cnt);
inc(v[cnt],va[j]);
end;
end;
end;
procedure spfa;
var e,t,now,l,r:longint;
begin
fillchar(p,sizeof(p),true);
fillchar(d,sizeof(d),);
l:=; r:=; f[]:=bl[s]; p[bl[s]]:=false; d[bl[s]]:=v[bl[s]]; //writeln(v[bl[s]]);
while l<=r do
begin
now:=f[l];
e:=h[now];
while e<> do
begin
t:=b[e].t;
//if t=1 then writeln('x',now,' ',v[t]);
if d[t]<d[now]+v[t] then
begin
d[t]:=d[now]+v[t];
if p[t] then
begin
p[t]:=false;
inc(r);
f[r]:=t;
end;
end;
e:=b[e].f;
end;
inc(l);
p[now]:=true;
end;
end;
begin
readln(n,m);
for i:= to m do
begin
readln(u,x);
insert(u,x);
end;
for i:= to n do readln(va[i]);
fillchar(p,sizeof(p),false);
for i:= to n do if dfn[i]= then tarjan(i);
readln(s,m);
readd;
//for i:=1 to 4 do writeln(v[i]);
spfa;
for i:= to m do
begin
read(u);
if d[bl[u]]>ans then ans:=d[bl[u]];
end;
writeln(ans);
end.
(转载请注明出处:http://www.cnblogs.com/Kalenda/)
P1179: [Apio2009]Atm的更多相关文章
- 【Tarjan】+【SPFA】APIO2009 Atm
一.算法介绍 tarjan——求解有向图强连通分量.这个算法在本人的一篇blog中有介绍,这里就不赘述了.贴上介绍tarjan的的blog链接:http://www.cnblogs.com/Maki- ...
- BZOJ 1179: [Apio2009]Atm( tarjan + 最短路 )
对于一个强连通分量, 一定是整个走或者不走, 所以tarjan缩点然后跑dijkstra. ------------------------------------------------------ ...
- 1179: [Apio2009]Atm
1179: [Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1629 Solved: 615[Submit][Status ...
- BZOJ1179 [Apio2009]Atm 【tarjan缩点】
1179: [Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MB Submit: 4048 Solved: 1762 [Submit][Sta ...
- bzoj 1179 [Apio2009]Atm 缩点+最短路
[Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 4290 Solved: 1893[Submit][Status][Dis ...
- 缩点+spfa最长路【bzoj】 1179: [Apio2009]Atm
[bzoj] 1179: [Apio2009]Atm Description Siruseri 城中的道路都是单向的.不同的道路由路口连接.按照法律的规定, 在每个路口都设立了一个 Siruseri ...
- BZOJ1179 : [Apio2009]Atm 缩点+spfa
1179: [Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 2069 Solved: 826[Submit][Status ...
- bzoj 1179[Apio2009]Atm (tarjan+spfa)
题目 输入 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号.接下来N行,每行一 ...
- bzoj1179 [Apio2009]Atm
Description Input 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口 ...
随机推荐
- Linux下多线程编程
一.为什么要引入线程? 使用多线程的理由之一是和进程相比,它是一种非常"节俭"的多任务操作方式.在Linux系统下,启动一个新的进程必须分配给它独立的地址空间,建立众多的数据表来维 ...
- Loadrunner:集合点(Rendezvous)
集合点:等到特定的用户数后再一起执行某个操作,比如一起登录.一起发信,一般情况下使用不到集合点,不过,订票系统或者促销类需要用到,比如说某个促销品的促销时间在8点到8点30,这样的话,就可能出现在8点 ...
- Mybatis配置
首先导入mybatis-3.2.3.jar包 还有连接数据库的驱动包 工程中必须导入的三个包(对应的包附件中可以下载): mybatis-3.2.3.jar sqljdbc.jar log ...
- Android IOS WebRTC 音视频开发总结(六二)-- 大数据解密国外实时通讯行业开发现状
本文主要介绍国外实时通讯行业现状,文章最早发表在我们的微信公众号上,详见这里,欢迎关注微信公众号blackerteam,更多详见www.blackerteam.com 上篇文章我们采用百度搜索指数来分 ...
- 移植u-boot-1.1.6之mtdparts分区
和u-boot高版本不同,mtdparts命令没有cmd_mtdparts这么一个单独的文件来实现. 不过,搜索uboot可以在cmd_jffs2.c里面看到如下代码: U_BOOT_CMD( mtd ...
- 开始记录blog
将自己的总结.新的记录下来,形成习惯,为以后的温故知新
- wpMVVM模式绑定集合的应用
一.新建一个项目,命名为wpMVVMone,添加一个有关食品信息的类Food.CS,代码如下: public class Food { public string Name { get; set; } ...
- [译]Cassandra的数据读写与压缩
本文翻译主要来自Datastax的cassandra1.2文档.http://www.datastax.com/documentation/cassandra/1.2/index.html.此外还有一 ...
- js原型链接(二)和object类的create方法
原型链的内部执行方式 <script> function Myclass(){ this.x=" x in Myclass"; } var obj=new Myclas ...
- ViewPager中GridView问题
GridView 嵌套在ViewPager中问题. 1. GridView属性设置无法显示. 正常显示方式 <GridView android:padding="8dip" ...