【BZOJ1179】[Apio2009]Atm (tarjan+SPFA)
显而易见的tarjan+spfa...不解释了
const maxn=;
type
edgetype=record
toward,next:longint;
end; var
edge1,edge2:array[..maxn] of edgetype;
first1,first2,scc,stack,dfn,low,val,sum,q,d:Array[..maxn] of longint;
pd:array[..maxn] of boolean;
num,tot,n,m,cnt,top:longint; function min(x,y:longint):longint; begin if x<y then exit(x) else exit(y); end; procedure addedge(i,j:longint);
begin
inc(tot);
edge1[tot].toward:=j;
edge1[tot].next:=first1[i];
first1[i]:=tot;
end; procedure add(i,j:longint);
begin
inc(tot);
edge2[tot].toward:=j;
edge2[tot].next:=first2[i];
first2[i]:=tot;
end; procedure tarjan(v:longint);
var i,tmp,u:longint;
begin
inc(cnt); dfn[v]:=cnt; low[v]:=cnt;
inc(top); stack[top]:=v;
pd[v]:=true; i:=first1[v];
while i<> do
begin
tmp:=edge1[i].toward;
if dfn[tmp]= then
begin
tarjan(tmp);
low[v]:=min(low[v],low[tmp]);
end
else if pd[tmp] then low[v]:=min(low[v],dfn[tmp]);
i:=edge1[i].next;
end;
if low[v]=dfn[v] then
begin
inc(num);
repeat
u:=stack[top]; dec(top);
pd[u]:=false; scc[u]:=num;
inc(sum[num],val[u]);
until u=v;
end;
end; procedure spfa(s:longint);
var head,tail,i,j,tmp:longint;
begin
fillchar(d,sizeof(d),);
fillchar(pd,sizeof(pd),false);
head:=;
tail:=;
pd[scc[s]]:=true;
q[]:=scc[s];
d[scc[s]]:=sum[scc[s]];
while head<>tail do
begin
inc(head);
if head>maxn then head:=;
j:=q[head];
i:=first2[j];
while i<> do
begin
tmp:=edge2[i].toward;
if d[j]+sum[tmp]>d[tmp] then
begin
d[tmp]:=d[j]+sum[tmp];
if not pd[tmp] then
begin
inc(tail); if tail>maxn then tail:=;
q[tail]:=tmp;
pd[tmp]:=true;
end;
end;
i:=edge2[i].next;
end;
pd[j]:=false;
end;
end; procedure init;
var i,j,a,b:longint;
begin
read(n,m);
for i:= to m do
begin
readln(a,b);
addedge(a,b);
end;
for i:= to n do read(val[i]);
for i:= to n do if dfn[i]= then tarjan(i);
end; procedure solve;
var p,x,ans,s,i,j:longint;
begin
read(s,p);
tot:=;
for j:= to n do
begin
i:=first1[j];
while i<> do
begin
x:=edge1[i].toward;
if scc[x]<>scc[j] then add(scc[j],scc[x]);
i:=edge1[i].next;
end;
end;
spfa(s);
ans:=;
for i:= to p do
begin
read(x);
if d[scc[x]]>ans then ans:=d[scc[x]];
end;
writeln(ans);
end; Begin
init;
solve;
End.
【BZOJ1179】[Apio2009]Atm (tarjan+SPFA)的更多相关文章
- 【BZOJ1179】 [Apio2009]Atm tarjan缩点+SPFA
Description Input 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口 ...
- 【bzoj1179】[Apio2009]Atm Tarjan缩点+Spfa最长路
题目描述 输入 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号.接下来N行,每 ...
- 【bzoj1179】 Apio2009—Atm
www.lydsy.com/JudgeOnline/problem.php?id=1179 (题目链接) 题意 给出一张有向图,每个节点有点权.标记一些点,找出一条路径,可以重复经过一条边,使得总点权 ...
- 【bzoj1179】[Apio2009]Atm
*题目描述: *输入: 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号.接下来 ...
- bzoj 1179[Apio2009]Atm (tarjan+spfa)
题目 输入 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号.接下来N行,每行一 ...
- 【BZOJ4651】【NOI2016】网格(Tarjan,哈希)
[BZOJ4651][NOI2016]网格(Tarjan,哈希) 题面 BZOJ 洛谷 题解 首先把题目稍微变得好说一些,给定一个网格,已经删去了若干个格子 问最少删去多少个格子使得图不连通. 这题的 ...
- 【BZOJ-1179】Atm Tarjan + SPFA
1179: [Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 2407 Solved: 993[Submit][Status ...
- 【Tarjan】+【SPFA】APIO2009 Atm
一.算法介绍 tarjan——求解有向图强连通分量.这个算法在本人的一篇blog中有介绍,这里就不赘述了.贴上介绍tarjan的的blog链接:http://www.cnblogs.com/Maki- ...
- 【BZOJ 1179】[Apio2009]Atm
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] tarjan强连通缩点一下. 然后把缩点之后,每个点的钱的数累加起来. 然后从S出发 开始一边做bfs一遍做dp. 最后输出有酒吧的 ...
随机推荐
- UITabBarController的tabBarItem图标真机不显示
在xib中分别设置了图标选择和未选择的图片 模拟器效果 选中 未选中 当时使用多种机型进行测试时发现部分机型第一次进入应用除第一个tabbaritem图标可以显示,其余均不能显示,点击其余tabbar ...
- Webpack4 学习笔记四 暴露全局变量、externals
前言 此内容是个人学习笔记,以便日后翻阅.非教程,如有错误还请指出 webpack 暴露全局变量 通过 expose-loader 内联配置 在 webpack中配置 每个模块通过注入的方式 通过CD ...
- swiper轮播始终居中active图片
用的是vue-awesome-swiper 在vue项目中,参数方法与swiper一致.使用场景如下: 左侧小图一共八张,默认显示的是三张,始终保持activeimg在中间,提升用户体验度.swipe ...
- Linux文件服务器实战(系统用户)
ftp匿名用户设置完成之后任何人都可以访问服务器端文件,目录,甚至可以修改删除文件和目录,,那如何存放私密文件并保证文件或者目录专属于拥有者呢,就需要使用vsftp系统用户来实现了. 1.在linux ...
- JAVAOOP异常
排序: Try-catch-finally:try正常执行,如果有异常执行catch后执行finally,如果没有直接执行finally 执行顺序:try-catch:try中的语句正常执行,如果遇到 ...
- 关于IT术语---ip、uv、pv、tps、qps、rps
涉及到IT方面的几条术语,这里要好好说道说道: 只要和网站打交道,难免会经常听到一系列的转有名词 >>> 系统今日UV多少.PV多少.QPS多少之类的问题.这里就对这些常见的术语 ...
- python scrapy实战糗事百科保存到json文件里
编写qsbk_spider.py爬虫文件 # -*- coding: utf-8 -*- import scrapy from qsbk.items import QsbkItem from scra ...
- 笔记-docker-3 使用
笔记-docker-3 使用 1. 镜像 image是docker最重要的概念,docker运行容器前需要本地存在对应的镜像,如果没有,会尝试从默认镜像库下载. 1.1. 镜像获取 查 ...
- 1,Python常用库之一:Numpy
Numpy支持大量的维度数组和矩阵运算,对数组运算提供了大量的数学函数库! Numpy比Python列表更具优势,其中一个优势便是速度.在对大型数组执行操作时,Numpy的速度比Python列表的速度 ...
- ThinkPad 触控板双指不可以滑动
我一直在想为什么,今天我想禁用触摸板的时候,我找到原因了. 是因为没有装驱动. http://think.lenovo.com.cn/support/driver/newdriversdownlist ...