显而易见的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)的更多相关文章

  1. 【BZOJ1179】 [Apio2009]Atm tarjan缩点+SPFA

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

  2. 【bzoj1179】[Apio2009]Atm Tarjan缩点+Spfa最长路

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

  3. 【bzoj1179】 Apio2009—Atm

    www.lydsy.com/JudgeOnline/problem.php?id=1179 (题目链接) 题意 给出一张有向图,每个节点有点权.标记一些点,找出一条路径,可以重复经过一条边,使得总点权 ...

  4. 【bzoj1179】[Apio2009]Atm

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

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

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

  6. 【BZOJ4651】【NOI2016】网格(Tarjan,哈希)

    [BZOJ4651][NOI2016]网格(Tarjan,哈希) 题面 BZOJ 洛谷 题解 首先把题目稍微变得好说一些,给定一个网格,已经删去了若干个格子 问最少删去多少个格子使得图不连通. 这题的 ...

  7. 【BZOJ-1179】Atm Tarjan + SPFA

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

  8. 【Tarjan】+【SPFA】APIO2009 Atm

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

  9. 【BZOJ 1179】[Apio2009]Atm

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] tarjan强连通缩点一下. 然后把缩点之后,每个点的钱的数累加起来. 然后从S出发 开始一边做bfs一遍做dp. 最后输出有酒吧的 ...

随机推荐

  1. java基础必备单词讲解 day five

    Rectangle width high height area employee tool param version author math guess resources 之前单词复习 path ...

  2. Scott Young-《如何高效学习》

    1.如果你只用一种方式了解某样事物,那么你就没有真正了解它.事情真正含义的秘密取决于我们如何将其与我们所了解的其他事情相联系.很好联系的内容可使你将想法融于脑中,从各种角度看问题,直至你找到合适自己的 ...

  3. Mac中Mysql开启远程访问(不同于linux直接改配置文件)

    在mac中安装Mysql Workbench 用root用户连上安装的Mysql.  开启远程访问的服务 如下图可以看到是root用户绑定的是localhost  如果不做修改的话,直接访问是访问不了 ...

  4. winrar压缩工具

    WinRAR使用心得 免广告 英文版可以设置广告关闭,地址: https://www.win-rar.com/predownload.html?&Version=64bit 把WinRAR默认 ...

  5. js面向(基于)对象编程—类(原型对象)与对象

    JS分三个部分: 1. ECMAScript标准--基础语法 2. DOM  Document Object Model 文档对象模型 3. BOM  Browser Object Moldel 浏览 ...

  6. keil5的安装及问题

    win8+keil 注意,在进行破解的时候首先要打开一个工程,而且keil要用管理员的身份进行运行, 才可以破解完成 发现打开之后,出现这样的错误. 原因是因为在创建工程的时候在下图中点了是,要点否才 ...

  7. 虚拟机linux桥接联网问题

    Linux系统为redhat5.8 虚拟机的版本:vm8.0 本人刚刚开始接触linux,今日需要通过linux进行联网,因此也学习了一点点关于虚拟机的联网的知识,在此与大家进行分享,希望大家可以之处 ...

  8. C语言数组篇(一)一维数组

       0.  数组的两种表现形式         一种是常见的a[10];         //初学者常用         另一种是用指针表示的数组.   //实际工程使用.常用于参数传递       ...

  9. 查找并绘制轮廓 opencv

    findContours(): 第二个参数为一个检测到的轮廓,函数调用后的运算结果都放在这里,每个轮廓存储为1个点向量,用point类型的vector表示. 第三个参数表示轮廓数量,包含了许多元素.每 ...

  10. python基础之正则表达式和re模块

    正则表达式 就其本质而言,正则表达式(或 re)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成一系列的字节码,然后由用 ...