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条道路的起点和终点的路口 ...
随机推荐
- C# 发送邮件方法
发送邮件所用的核心知识点 微软封装好的MailMessage类:主要处理发送邮件的内容(如:收发人地址.标题.主体.图片等等) 微软封装好的SmtpClient类:主要处理用smtp方式发送此邮件的配 ...
- dig out deledted chat messages
One of my friends asked me to do a favor for her. She said her friend deleted some important chat me ...
- Excel2007给表格设置成只读加密属性 让他人无法修改
在制作一些报表和公司的表格时,我们常常需要给Excel表格加密或者设置成只读属性来加以防护这些重要表格.给表格加密可以预防他人无法打开表格,只有通过输入正确的密码后才可以正常打开.设置成只读的话,可以 ...
- leetcode 36
36. Valid Sudoku Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudok ...
- 打造一个自动检测页面是否存在XSS的小插件
前言: 还记得刚玩Web安全时,就想着要是能有一个自动挖掘XSS漏洞的软件就好了.然后我发现了Safe3.JSky.AWVS.Netsparker等等,但是误报太多,而且特别占内存.后来发现了fidd ...
- Velocity语法大全
1\ 参考地址:http://www.cnblogs.com/codingsilence/archive/2011/03/29/2146580.html
- MVC开发Markdown编辑器(1)
MVC markdown MVC开发Markdown编辑器(1) 前言 安装 解析 结束语 前言 想在近段时间通过mvc开发个人博客,编辑器希望是markdown风格的,这样写文字会很方便.首先先解决 ...
- varnish状态引擎1
vcl: state engine:各引擎之间存一定程度上的相关性:前一个engine如果可以有多种下游engine,则上游engine需要用return指明 要转移的下游engine vcl_rec ...
- 配置NTP服务ntpd/ntp.conf(搭建Hadoop集群可参考)
本文拟定是在一个局域网内(比如一个Hadoop集群)设定一台NTP服务器作为整个网络的标准时间参考,使用网络(集群)内的所有机器保持时间一致!以下是详细的操作步骤: 1. 修改选定的服务器的本地时间 ...
- 配置Nginx服务
一,安装之前准备1.nginx依赖: gcc openssl-devel pcre-devel zlib-devel 安装依赖:yum install gcc openssl-devel pcr ...