http://www.lydsy.com/JudgeOnline/problem.php?id=1179

缩点建图。。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; } const int N=1000005, oo=~0u>>1; int FF[N], LL[N], scc, p[N], vis[N], s[N], top, tot, d[N];
struct GR {
int ihead[N], cnt, n, w[N];
struct dat { int to, next; }e[N];
void add(int u, int v) {
e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v;
}
void tarjan(int x) {
FF[x]=LL[x]=++tot; vis[x]=1; s[++top]=x;
int y;
rdm(x, i) {
y=e[i].to;
if(!FF[y]) tarjan(y), LL[x]=min(LL[x], LL[y]);
else if(vis[y]) LL[x]=min(LL[x], FF[y]);
}
if(LL[x]==FF[x]) {
++scc;
do {
y=s[top--];
vis[y]=0;
p[y]=scc;
} while(x!=y);
}
}
void tarjan() { for1(i, 1, n) if(!FF[i]) tarjan(i); }
void spfa(int x) {
for1(i, 1, n) d[i]=-oo, vis[i]=0;
d[x]=w[x]; vis[x]=1;
int front, tail; front=tail=0;
int *q=s;
q[tail++]=x;
while(front!=tail) {
int u=q[front++], v; if(front==N) front=0; vis[u]=0;
rdm(u, i) if(d[e[i].to]<d[u]+w[e[i].to]) {
v=e[i].to;
d[v]=d[u]+w[v];
if(!vis[v]) {
vis[v]=1;
if(d[q[front]]<d[v]) {
--front; if(front<0) front+=N;
q[front]=v;
}
else {
q[tail++]=v; if(tail==N) tail=0;
}
}
}
}
}
}G, g; void build() {
G.tarjan();
g.n=scc;
for1(i, 1, G.n) g.w[p[i]]+=G.w[i];
for1(x, 1, G.n) for(int i=G.ihead[x]; i; i=G.e[i].next) if(p[x]!=p[G.e[i].to]) g.add(p[x], p[G.e[i].to]);
} int n, m, ans, num, bar[N];
int main() {
read(n); read(m); G.n=n;
for1(i, 1, m) { int u=getint(), v=getint(); G.add(u, v); }
for1(i, 1, n) read(G.w[i]);
int s=getint(); read(num);
build();
g.spfa(p[s]);
for1(i, 1, num) read(bar[i]);
for1(i, 1, num) ans=max(ans, d[p[bar[i]]]);
printf("%d\n", ans);
return 0;
}

  


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的单向的道路到达其中的至少一个酒吧。

Source

【BZOJ】1179: [Apio2009]Atm(tarjan+spfa)的更多相关文章

  1. 缩点+spfa最长路【bzoj】 1179: [Apio2009]Atm

    [bzoj] 1179: [Apio2009]Atm Description Siruseri 城中的道路都是单向的.不同的道路由路口连接.按照法律的规定, 在每个路口都设立了一个 Siruseri ...

  2. BZOJ 1179 [Apio2009]Atm(强连通分量)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1179 [题目大意] 给出一张有向带环点权图,给出一些终点,在路径中同一个点的点权只能累 ...

  3. 【BZOJ】1027: [JSOI2007]合金(凸包+floyd)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1027 题意:$n$种材料,$m$种需求.每种材料有三个属性,给出三个属性的含量(和为1),问能否通过 ...

  4. 【BZOJ】1101: [POI2007]Zap(莫比乌斯+分块)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1101 无限膜拜数论和分块orz 首先莫比乌斯函数的一些性质可以看<初等数论>或<具 ...

  5. 【BZOJ】3527: [Zjoi2014]力(fft+卷积)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3527 好好的一道模板题,我自己被自己坑了好久.. 首先题目看错.......什么玩意.......首 ...

  6. 【BZOJ】1082: [SCOI2005]栅栏(二分+dfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1082 题意:n个给出木板,m个给出木板.可以将那m个木板锯成泥想要的长度.问最大能锯成多少个给出的n ...

  7. 【BZOJ】1066: [SCOI2007]蜥蜴(最大流)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1066 本题想一想应该懂了的. 我们想啊,,每个点都有限制,每个点都可以跳到另一个有限制的点,每个有蜥 ...

  8. 【BZOJ】3172: [Tjoi2013]单词(后缀自动机)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3172 随便搞个sam就行了.(其实一开始看到数据n<=200, 单词长度不超过1e6,然后感觉 ...

  9. 【BZOJ】1176: [Balkan2007]Mokia(cdq分治)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1176 在写这题的时候思维非常逗啊........2333................... 最后 ...

随机推荐

  1. linux expect 简单讲解

    来自http://blog.csdn.net/winstary/archive/2009/08/08/4422156.aspx使用expect实现自动登录的脚本,网上有很多,可是都没有一个明白的说明, ...

  2. 【VirtualBox】VirtualBox的桥接网络模式,为啥网络不稳定?

    网桥模式访问外网非常慢,经常卡死,ping时断时续 七搞八搞,反复重启了几次 TMD  就好了,也不知道什么情况,VirtualBox还是不太好使啊..... 网桥模式 设置 如下: 参考资料: ht ...

  3. 【Linux】为啥查某个进程的线程,查出来的所有线程的pid不一样啊

    楼上说的linux线程和进程是一样的,这个说法是错误的. 看了楼主的问题,感觉楼主是被PID给弄混了,线程进程都会有自己的ID,这个ID就叫做PID,PID是不特指进程ID,线程ID也可以叫做PID. ...

  4. 44. log(n)求a的n次方[power(a,n)]

    [题目] 实现函数double Power(double base, int exponent),求base的exponent次方,不需要考虑溢出. [分析] 这是一道看起来很简单的问题,很容易写出如 ...

  5. maven web项目build失败

    通过maven build发布web项目到tomcat时报如下异常: [INFO] ---------------------------------------------------------- ...

  6. 手动创建第一个JSP应用

    当按照上一篇文章所说的,配置好了tomcat服务器之后,我们就可以开发运行在tomcat上的第一个web应用了,在对tomcat的目录了解之后,我们知道webapps是存放我们编写相应应用程序的目录, ...

  7. Ubuntu 13.04安装搜狗输入法

    Ubuntu 13.04安装搜狗输入法 [日期:2013-07-08] 来源:Linux公社  作者:LinuxIDC.com [字体:大 中 小]     目标:在Ubuntu 13.04以及基于U ...

  8. Android activity_main.xml删除边缘距离,充满屏幕

    删除android:paddingBottom.android:paddingLeft.android:paddingRight和android:paddingTop四个属性

  9. Mac 安装Java JDK

    (一)Java JDK 首先到该网址,下载JavaSE  http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads- ...

  10. 越狱后天气闪退 iPhone5天气闪退解决方法

    iPhone5天气闪退解决方法: 第一步:前往Cydia卸载AppSync; 第二步:通过iTools删除/var/mobile/Library/Caches/com.apple.mobile.ins ...