缩点+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的更多相关文章

  1. 【Tarjan】+【SPFA】APIO2009 Atm

    一.算法介绍 tarjan——求解有向图强连通分量.这个算法在本人的一篇blog中有介绍,这里就不赘述了.贴上介绍tarjan的的blog链接:http://www.cnblogs.com/Maki- ...

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

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

  3. 1179: [Apio2009]Atm

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

  4. BZOJ1179 [Apio2009]Atm 【tarjan缩点】

    1179: [Apio2009]Atm Time Limit: 15 Sec  Memory Limit: 162 MB Submit: 4048  Solved: 1762 [Submit][Sta ...

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

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

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

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

  7. BZOJ1179 : [Apio2009]Atm 缩点+spfa

    1179: [Apio2009]Atm Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 2069  Solved: 826[Submit][Status ...

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

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

  9. bzoj1179 [Apio2009]Atm

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

随机推荐

  1. 理解DOM中的事件流

    浏览器发展到第四代时(IE4和Netscape Communicator 4),浏览器团队遇到一个很有意思的问题:页面的哪一部分会拥有特定的事件?想象下在一张纸上有一组同心圆,如果你把手指放在圆心上, ...

  2. 二十二、OGNL的一些其他操作

    二十二.OGNL的一些其他操作 投影 ?判断满足条件 动作类代码: ^ $   public class Demo2Action extends ActionSupport {     public ...

  3. Windows服务编程Demo

    实现一个开机自动启动的关机程序,具体代码如下: #include <Windows.h> void ServiceMain(); void ControlHandler(DWORD req ...

  4. s3c6410_MMU地址映射过程详述

    参考: 1)<ARM1176 JZF-S Technical Reference Manual>: Chapter 3 System Control Coprocessor Chapter ...

  5. datagridview添加复选框全选和取消

    全选 private void All_selected_Click(object sender, EventArgs e) { ; i < this.DataGridViewProduct.R ...

  6. c# 数据库操作学习

    一. 如何处理数据库连接 1. 数据库连接可以分为“物理连接”和“逻辑连接”(默认使用连接池的情况下Pooling=true): 物理连接:创建数据库连接时,默认会有一定数量的物理连接(默认Min P ...

  7. MapReduce框架Partitioner分区方法

    前言:对于二次排序相信大家也是似懂非懂,我也是一样,对其中的很多方法都不理解诶,所有只有暂时放在一边,当你接触到其他的函数,你知道的越多时你对二次排序的理解也就更深入了,同时建议大家对wordcoun ...

  8. 瀑布流ListView

    前言 终于忙完了一段时间,现在前段时间写的一个瀑布流ListView到想法分享下,这个东西是扩展自Listview,当列表内容拉到最后后触发刷新操作,以便抓取更多到数据. 先贴下整个代码,先有个整体到 ...

  9. php生成excel文件的简单方法

    生成excel文件,最简单的莫过于把数据库的数据导入到excel就行了. 生成excel 当然使用的是 phpExcel http://www.jbxue.com/tags/phpexcel.html ...

  10. HDFS文件读写流程

    一.HDFS HDFS全称是Hadoop Distributed System.HDFS是为以流的方式存取大文件而设计的.适用于几百MB,GB以及TB,并写一次读多次的场合.而对于低延时数据访问.大量 ...