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. OpenCASCADE动画功能

    OpenCASCADE动画功能 eryar@163.com 1.Introduction OpenCASCADE提供了类AIS_Animation等来实现简单的动画功能. 从其类图可以看出,动画功能有 ...

  2. Flink中的多source+event watermark测试

    这次需要做一个监控项目,全网日志的指标计算,上线的话,计算量应该是百亿/天 单个source对应的sql如下 最原始的sql select pro,throwable,level,ip,`count` ...

  3. HDFS 冗余数据保存

  4. 1858: [Scoi2010]序列操作

    1858: [Scoi2010]序列操作 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 3397 Solved: 1624 [Submit][Statu ...

  5. leetcode 492-543 easy

    492. Construct the Rectangle Input: 4 Output: [2, 2] Explanation: The target area is 4, and all the ...

  6. TZ_09_常用jQuery操作

    1.实现对chexkbox进行批量删除 checkbox属性 <td><input name="ids" type="checkbox" va ...

  7. vue跨域,复杂请求,后端为beego

    关于跨域,网上讲得很多,具体实施起来大多讲的不详细,贴我的vue端代码 require('es6-promise').polyfill() import fetch from 'isomorphic- ...

  8. NOIP模拟赛 6.29

    2017-6-29 NOIP模拟赛 Problem 1 机器人(robot.cpp/c/pas) [题目描述] 早苗入手了最新的Gundam模型.最新款自然有着与以往不同的功能,那就是它能够自动行走, ...

  9. Ubuntu上更换163源 - Mars Loo的博客

    转载*请注明原始出处:http://blog.csdn.net/a464057216/article/details/50865895 先备份源/etc/apt/sources.list为source ...

  10. spring和mybatis整合遇到org.springframework.beans.factory.BeanDefinitionStoreException

    今天对spring和mybatis整合进行练习,通过MapperScannerConfigurer进行mapper扫描 但是在进行单元测试的时候,死活就是报错,具体报错如下: org.springfr ...