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最大路

  1. //Serene
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cstring>
  5. #include<cstdlib>
  6. #include<cstdio>
  7. #include<cmath>
  8. #include<set>
  9. using namespace std;
  10. const int maxn=5e5+10,INF=2e9+5;
  11. int n,m,S,v[maxn],ans;
  12. set<int> G;
  13. set<int>::iterator it;
  14.  
  15. int aa;char cc;
  16. int read() {
  17. aa=0;cc=getchar();
  18. while(cc<'0'||cc>'9') cc=getchar();
  19. while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar();
  20. return aa;
  21. }
  22.  
  23. int fir[maxn],nxt[maxn],to[maxn],e=0;
  24. void add(int x,int y) {
  25. to[++e]=y;nxt[e]=fir[x];fir[x]=e;
  26. }
  27.  
  28. int id[maxn],top[maxn],zz[maxn],d=0,tf=0;
  29. int xd[maxn],sum[maxn],tot;
  30. bool vis[maxn],inz[maxn];
  31. void tj(int pos) {
  32. id[pos]=top[pos]=++d;zz[++tf]=pos;
  33. vis[pos]=inz[pos]=1;
  34. for(int y=fir[pos];y;y=nxt[y]) {
  35. if(vis[to[y]]) {
  36. if(inz[to[y]]) top[pos]=min(top[pos],top[to[y]]);
  37. continue;
  38. }
  39. tj(to[y]);top[pos]=min(top[pos],top[to[y]]);
  40. }
  41. if(top[pos]==id[pos]) {
  42. sum[++tot]=0;
  43. while(tf) {
  44. sum[tot]+=v[zz[tf]];
  45. xd[zz[tf]]=tot;
  46. inz[zz[tf]]=0;
  47. tf--;
  48. if(zz[tf+1]==pos) break;
  49. }
  50. }
  51. }
  52.  
  53. int ff[maxn],nn[maxn],tt[maxn],ee=0;
  54. void bld(int x,int y) {
  55. tt[++ee]=y;nn[ee]=ff[x];ff[x]=ee;
  56. }
  57.  
  58. int dis[maxn];
  59. void spfa(int st) {
  60. memset(zz,0,sizeof(zz));
  61. memset(vis,0,sizeof(vis));
  62. int s=1,t=0,x,y,z;
  63. zz[++t]=st;vis[st]=1;
  64. memcpy(dis,sum,sizeof(sum));
  65. while(s<=t) {
  66. x=zz[s%maxn];
  67. for(y=ff[x];y;y=nn[y]) {
  68. z=tt[y];
  69. if(dis[z]>=dis[x]+sum[z]) continue;
  70. dis[z]=dis[x]+sum[z];
  71. if(!vis[z]) {
  72. vis[z]=1;t++;
  73. zz[t%maxn]=z;
  74. }
  75. }
  76. s++;vis[x]=0;
  77. }
  78. }
  79.  
  80. int main() {
  81. n=read();m=read(); int x,y;
  82. for(int i=1;i<=m;++i) {
  83. x=read();y=read();
  84. add(x,y);
  85. }
  86. for(int i=1;i<=n;++i) v[i]=read();
  87. S=read();x=read();
  88. for(int i=1;i<=x;++i) {
  89. y=read();G.insert(y);
  90. }
  91. tj(S);
  92. for(int i=1;i<=n;++i) for(int y=fir[i];y;y=nxt[y])
  93. if(xd[i]!=xd[to[y]]) bld(xd[i],xd[to[y]]);
  94. spfa(xd[S]);
  95. for(it=G.begin();it!=G.end();++it) {
  96. x=xd[*it];ans=max(ans,dis[x]);
  97. }
  98. printf("%d",ans);
  99. return 0;
  100. }

  

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. Vue 提示框组件

    OK,首先看看效果: 一.子组件(alert.vue) <template> <transition name="alert"> <div class ...

  2. 爬虫的终极形态:nightmare

    爬虫的终极形态:nightmare nightmare 是一个基于 electron 的自动化库(意思是说它自带浏览器),用于实现爬虫或自动化测试.相较于传统的爬虫框架(scrapy/pyspider ...

  3. Java常用的数据结构

    collection : List:arrayList,linkedList,vector set:treeSet ,hashSet; map: hashMap treeMap linkedHashM ...

  4. ORACLE忘记sys密码

    1.win+R打开dos窗口cmd 2.输入 sqlplus/nolog出现 3.输入 conn / as sysdba 出现 4.修改密码 alter user 用户 identified by 新 ...

  5. 洛谷P2827 蚯蚓

    传送门 pts85/90(90应该是个意外,第一次交是90之后都是85了): 优先队列模拟题意 #include<iostream> #include<cstdio> #inc ...

  6. python-pygame安装教程

    网上有很多关于python,pygame的安装教程.大都比较麻烦,下面为大家介绍一种非常简单的安装方法.(因为安装大都是新手教程写详细一些) python是32位 python是3.6 1 pip配置 ...

  7. PHP生成linux命令行进度条

    <?php$total = 100; for ($i = 1; $i <= $total; $i++) { printf("progress: [%-50s] %d%% Done ...

  8. tomcat9 gzip

    我认为apr模式比较屌所以 <Connector port=" protocol="org.apache.coyote.http11.Http11AprProtocol&qu ...

  9. hql 条件查询 返回空的一种情况

    为何会出现查询为空,但是查询整个表没问题的情况呢? 这里是没有分清字符串和变量 原来写的是, String hql = "from ClientInfoModel where clientI ...

  10. 一致性Hash算法原理,java实现,及用途

    学习记录: 一致性Hash算法原理及java实现:https://blog.csdn.net/suifeng629/article/details/81567777 一致性Hash算法介绍,原理,及使 ...