【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. 最后输出有酒吧的 ...
随机推荐
- java基础 java中枚举的应用 抽象方法问题
package com.swift.meiju; import org.junit.Test; public class Demo{ @Test public void test() { System ...
- 如何将一个div水平垂直居中
方案一: div绝对定位水平垂直居中[margin:auto实现绝对定位元素的居中], 兼容性:,IE7及之前版本不支持 div{ width: 200px; height: 200px; backg ...
- Fetch 头像剪切修改
前言:通过Input file upload 图片到canvas 中进行剪裁,react 可以引入react-avatar-editor对图片进行剪裁 react-avatar-editor的使用 & ...
- selenium库:自动化测试工具
爬虫中主要用来解决Javascript渲染问题 1.声明浏览器对象: from selenium import webdriver browser = webdriver.浏览器名() 2.访问页面: ...
- windows系统下用VScode配置远程编辑服务器文件的环境!通过Rmate方法
虽然公司电脑win可以通过Xshell通过SSH远程连接家中内网linux服务器了,但是只能用vim编辑文件有点不爽. 于是上网查询,windows下使用vscode远程编辑服务器文件的办法.参照博文 ...
- 基本形状的绘制&添加文字
本次用opencv在图像上绘制了线,矩形,椭圆,圆的形状和放置了文字. #include<iostream> using namespace std; using namespace cv ...
- P2344 奶牛抗议
P2344 奶牛抗议 题目背景 Generic Cow Protests, 2011 Feb 题目描述 约翰家的N 头奶牛正在排队游行抗议.一些奶牛情绪激动,约翰测算下来,排在第i 位的奶牛的理智度为 ...
- centos使用--开机启动
centos6.8 1.利用 chkconfig 来配置启动级别 在CentOS或者RedHat其他系统下,如果是后面安装的服务,如httpd.mysqld.postfix等,安装后系统默认不会自动启 ...
- PJSIP-PJLIB(samples) (the usage of the pjlib lib) (eg:string/I/O)
Here are some samples about PJLIB! PJLIB is the basic lib of PJSIP, so we need master the lib first ...
- 剑指Offer - 九度1513 - 二进制中1的个数
剑指Offer - 九度1513 - 二进制中1的个数2013-11-29 23:35 题目描述: 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 输入: 输入可能包含多个测试样例. ...