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条道路的起点和终点的路口 ...
随机推荐
- Jsp servlet 值传递。。
先新建一个动态WEB项目. 展开WebRoot/index.jsp 1 <%@ page language="java" import="java.util.*&q ...
- Yii cookie 的使用方法
设置cookie: //首先新建cookie$cookie = new CHttpCookie('mycookie', 'this is my cookie');//定义cookie的有效期$cook ...
- MITM to crack Https connections
Everybody knows that https is http over SSL, and https is a secure way for protecting confidential d ...
- PayPal 开发详解(五):创建第一个应用,获取clientId和clientSecret
1.创建APP 2.填写应用名称->创建应用 3.获取 clientId 和 clientSecret
- File Manager文件管理应用android源码
这个刚刚在安卓教程网那里看到的,File Manager文件管理应用android源码,这个是File Manager文件管理应用源码,源码filemanager,一个开源的文件管理器完整源码,文件查 ...
- 鼠标HOVER时区块动画旋转变色的CSS3样式掩码
鼠标hover时区块动画旋转变色的css3样式掩码<!DOCTYPE html> <html> <head> <meta charset="utf- ...
- 举例详解CSS中的的优先级
计算优先级 优先级是根据由每种选择器类型构成的级联字串计算而成的.他是一个对应匹配表达式的权重. 如果优先级相同,靠后的 CSS 会应用到元素上. 注意:元素在文档树中的位置是不会影响优先级的优先级顺 ...
- iOS 技术博客分享
1.了解有什么新技术 1> 苹果API文档 - General - Guides - iOSx API Diffs 2> 观看WWDC会议视频 2.如何使用新技术 1> 自己根据AP ...
- 【自己动手】sublime text插件开发
今天是五四青年节,在此先祝大家节日快乐!!! --------------------------------------------华丽的分界线--------------------------- ...
- perl thread
#!/usr/local/bin/perl use threads; @domain = ("tom.com", "chinadns.com", "1 ...