Description

Input

第一行包含两个整数N、M。N表示路口的个数,M表示道路条数。接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号。接下来N行,每行一个整数,按顺序表示每个路口处的ATM机中的钱数。接下来一行包含两个整数S、P,S表示市中心的编号,也就是出发的路口。P表示酒吧数目。接下来的一行中有P个整数,表示P个有酒吧的路口的编号

Output

输出一个整数,表示Banditji从市中心开始到某个酒吧结束所能抢劫的最多的现金总数。

Sample Input

6 7
1 2
2 3
3 5
2 4
4 1
2 6
6 5
10
12
8
16
1 5
1 4
4
3
5
6

Sample Output

47

HINT

50%的输入保证N, M<=3000。所有的输入保证N, M<=500000。每个ATM机中可取的钱数为一个非负整数且不超过4000。输入数据保证你可以从市中心沿着Siruseri的单向的道路到达其中的至少一个酒吧。

缩点+spfa最大路

//Serene
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<set>
using namespace std;
const int maxn=5e5+10,INF=2e9+5;
int n,m,S,v[maxn],ans;
set<int> G;
set<int>::iterator it; int aa;char cc;
int read() {
aa=0;cc=getchar();
while(cc<'0'||cc>'9') cc=getchar();
while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar();
return aa;
} int fir[maxn],nxt[maxn],to[maxn],e=0;
void add(int x,int y) {
to[++e]=y;nxt[e]=fir[x];fir[x]=e;
} int id[maxn],top[maxn],zz[maxn],d=0,tf=0;
int xd[maxn],sum[maxn],tot;
bool vis[maxn],inz[maxn];
void tj(int pos) {
id[pos]=top[pos]=++d;zz[++tf]=pos;
vis[pos]=inz[pos]=1;
for(int y=fir[pos];y;y=nxt[y]) {
if(vis[to[y]]) {
if(inz[to[y]]) top[pos]=min(top[pos],top[to[y]]);
continue;
}
tj(to[y]);top[pos]=min(top[pos],top[to[y]]);
}
if(top[pos]==id[pos]) {
sum[++tot]=0;
while(tf) {
sum[tot]+=v[zz[tf]];
xd[zz[tf]]=tot;
inz[zz[tf]]=0;
tf--;
if(zz[tf+1]==pos) break;
}
}
} int ff[maxn],nn[maxn],tt[maxn],ee=0;
void bld(int x,int y) {
tt[++ee]=y;nn[ee]=ff[x];ff[x]=ee;
} int dis[maxn];
void spfa(int st) {
memset(zz,0,sizeof(zz));
memset(vis,0,sizeof(vis));
int s=1,t=0,x,y,z;
zz[++t]=st;vis[st]=1;
memcpy(dis,sum,sizeof(sum));
while(s<=t) {
x=zz[s%maxn];
for(y=ff[x];y;y=nn[y]) {
z=tt[y];
if(dis[z]>=dis[x]+sum[z]) continue;
dis[z]=dis[x]+sum[z];
if(!vis[z]) {
vis[z]=1;t++;
zz[t%maxn]=z;
}
}
s++;vis[x]=0;
}
} int main() {
n=read();m=read(); int x,y;
for(int i=1;i<=m;++i) {
x=read();y=read();
add(x,y);
}
for(int i=1;i<=n;++i) v[i]=read();
S=read();x=read();
for(int i=1;i<=x;++i) {
y=read();G.insert(y);
}
tj(S);
for(int i=1;i<=n;++i) for(int y=fir[i];y;y=nxt[y])
if(xd[i]!=xd[to[y]]) bld(xd[i],xd[to[y]]);
spfa(xd[S]);
for(it=G.begin();it!=G.end();++it) {
x=xd[*it];ans=max(ans,dis[x]);
}
printf("%d",ans);
return 0;
}

  

bzoj1179 Atm的更多相关文章

  1. BZOJ1179 Atm //缩点+spfa

    1179: [Apio2009]Atm Description Input 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的 ...

  2. 【Apio2009】Bzoj1179 Atm

    目录 List Description Input Output Sample Input Sample Output HINT Solution Code Dfs 记忆化搜索 Position: h ...

  3. [Apio2009][bzoj1179]Atm

    题意:一个n个点m条单向边的图,每个点有权值,给定出发点和p个可以停止的点,你可以随便走一条路径从出发点走到一个可以停止的点,但是每个点的点权只能计算一次,求能得到的最大权值. n,m<=500 ...

  4. [BZOJ1177][BZOJ1178][BZOJ1179]APIO2009解题报告

    抱着好奇心态去开始做APIO的往年试题感受一下难度 Oil Description 采油区域 Siruseri政府决定将石油资源丰富的Navalur省的土地拍卖给私人承包商以建立油井.被拍卖的整块土地 ...

  5. [BZOJ1179][APIO2009][强连通分量Tarjan+spfa]ATM

    [BZOJ1179][APIO2009]ATM Input 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i ...

  6. bzoj1179(Atm)

    ---恢复内容开始--- 1179: [Apio2009]Atm Time Limit: 15 Sec  Memory Limit: 162 MB Description Input 第一行包含两个整 ...

  7. 【BZOJ-1179】Atm Tarjan + SPFA

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

  8. bzoj1179 [Apio2009]Atm

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

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

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

随机推荐

  1. JS中apply和call的联系和区别

    以下内容翻译自stackoverflow 链接: http://stackoverflow.com/questions/7238962/function-apply-not-using-thisarg ...

  2. Consul3-使用consul作为配置中心

    在前面的文章中学习了consul在windows下的安装配置,然后consul作为spring boot的服务发现和注册中心,详细的参考: https://blog.csdn.net/j9038291 ...

  3. 《数据结构与算法分析——C语言描述》ADT实现(NO.00) : 链表(Linked-List)

    开始学习数据结构,使用的教材是机械工业出版社的<数据结构与算法分析——C语言描述>,计划将书中的ADT用C语言实现一遍,记录于此.下面是第一个最简单的结构——链表. 链表(Linked-L ...

  4. 【html、CSS、javascript-5】css应用场景补充

    一.CSS全局应用 父标签div下包含两个子标签div,当子标签dvi全部向左float,此时父标签设置的背景色是不显示的 <!DOCTYPE html> <html lang=&q ...

  5. Wamp PHP 安装各种拓展

    安装redis 下载dll文件地址:http://pecl.php.net/package/redis 下载对应版本nginx:NTS apache:TS 文件放在php的ext目录下 php.ini ...

  6. JS---元素隐藏的不同方式

    元素隐藏的不同方式 dispaly, visibility, opacity, height&border 为0 <!DOCTYPE html> <html lang=&qu ...

  7. Oracle中函数如何返回结果集

    在Oracle中,用函数返回结果集有时候要用到,下面是demo: 1 2 3 4 5 6 7 create or replace type t_test as object ( id integer, ...

  8. Linux下根目录root扩容

    参考博客:https://blog.csdn.net/qq_36527339/article/details/81772996 1.首先虚拟机关机 —> 选中要扩容的虚拟机 —>编辑虚拟机 ...

  9. Java中用JXL导出Excel代码详解

    jxl是一个韩国人写的java操作excel的工具, 在开源世界中,有两套比较有影响的API可供使用,一个是POI,一个是jExcelAPI.其中功能相对POI比较弱一点.但jExcelAPI对中文支 ...

  10. 洛谷P1029 最大公约数和最小公倍数问题 [2017年6月计划 数论02]

    P1029 最大公约数和最小公倍数问题 题目描述 输入二个正整数x0,y0(2<=x0<100000,2<=y0<=1000000),求出满足下列条件的P,Q的个数 条件: 1 ...