bzoj1179 Atm
Description
Input
第一行包含两个整数N、M。N表示路口的个数,M表示道路条数。接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号。接下来N行,每行一个整数,按顺序表示每个路口处的ATM机中的钱数。接下来一行包含两个整数S、P,S表示市中心的编号,也就是出发的路口。P表示酒吧数目。接下来的一行中有P个整数,表示P个有酒吧的路口的编号
Output
输出一个整数,表示Banditji从市中心开始到某个酒吧结束所能抢劫的最多的现金总数。
Sample Input
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
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的更多相关文章
- BZOJ1179 Atm //缩点+spfa
1179: [Apio2009]Atm Description Input 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的 ...
- 【Apio2009】Bzoj1179 Atm
目录 List Description Input Output Sample Input Sample Output HINT Solution Code Dfs 记忆化搜索 Position: h ...
- [Apio2009][bzoj1179]Atm
题意:一个n个点m条单向边的图,每个点有权值,给定出发点和p个可以停止的点,你可以随便走一条路径从出发点走到一个可以停止的点,但是每个点的点权只能计算一次,求能得到的最大权值. n,m<=500 ...
- [BZOJ1177][BZOJ1178][BZOJ1179]APIO2009解题报告
抱着好奇心态去开始做APIO的往年试题感受一下难度 Oil Description 采油区域 Siruseri政府决定将石油资源丰富的Navalur省的土地拍卖给私人承包商以建立油井.被拍卖的整块土地 ...
- [BZOJ1179][APIO2009][强连通分量Tarjan+spfa]ATM
[BZOJ1179][APIO2009]ATM Input 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i ...
- bzoj1179(Atm)
---恢复内容开始--- 1179: [Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MB Description Input 第一行包含两个整 ...
- 【BZOJ-1179】Atm Tarjan + SPFA
1179: [Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 2407 Solved: 993[Submit][Status ...
- bzoj1179 [Apio2009]Atm
Description Input 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口 ...
- 【BZOJ1179】 [Apio2009]Atm tarjan缩点+SPFA
Description Input 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口 ...
随机推荐
- Vue 提示框组件
OK,首先看看效果: 一.子组件(alert.vue) <template> <transition name="alert"> <div class ...
- 爬虫的终极形态:nightmare
爬虫的终极形态:nightmare nightmare 是一个基于 electron 的自动化库(意思是说它自带浏览器),用于实现爬虫或自动化测试.相较于传统的爬虫框架(scrapy/pyspider ...
- Java常用的数据结构
collection : List:arrayList,linkedList,vector set:treeSet ,hashSet; map: hashMap treeMap linkedHashM ...
- ORACLE忘记sys密码
1.win+R打开dos窗口cmd 2.输入 sqlplus/nolog出现 3.输入 conn / as sysdba 出现 4.修改密码 alter user 用户 identified by 新 ...
- 洛谷P2827 蚯蚓
传送门 pts85/90(90应该是个意外,第一次交是90之后都是85了): 优先队列模拟题意 #include<iostream> #include<cstdio> #inc ...
- python-pygame安装教程
网上有很多关于python,pygame的安装教程.大都比较麻烦,下面为大家介绍一种非常简单的安装方法.(因为安装大都是新手教程写详细一些) python是32位 python是3.6 1 pip配置 ...
- PHP生成linux命令行进度条
<?php$total = 100; for ($i = 1; $i <= $total; $i++) { printf("progress: [%-50s] %d%% Done ...
- tomcat9 gzip
我认为apr模式比较屌所以 <Connector port=" protocol="org.apache.coyote.http11.Http11AprProtocol&qu ...
- hql 条件查询 返回空的一种情况
为何会出现查询为空,但是查询整个表没问题的情况呢? 这里是没有分清字符串和变量 原来写的是, String hql = "from ClientInfoModel where clientI ...
- 一致性Hash算法原理,java实现,及用途
学习记录: 一致性Hash算法原理及java实现:https://blog.csdn.net/suifeng629/article/details/81567777 一致性Hash算法介绍,原理,及使 ...