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. C语言 单引号和双引号的区别

    最近的C语言课在教字符串,貌似N多同学搞不清楚单引号和双引号的区别,有人还以为在C语言里用哪个都可以...其实C语言中的单引号和双引号含义是一点也不一样滴... 1.含义不同. 用单引号引起的一个字符 ...

  2. How can I pretty-print JSON in python?

    python -m json.tool my_json.json 转自: http://stackoverflow.com/questions/352098/how-can-i-pretty-prin ...

  3. Django对静态文件的处理——部署阶段

    参考:http://blog.makto.me/post/2012-11-09/static-files-in-django-deployment HTML模板中的用法: {% load static ...

  4. codeforces 374A Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行  m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...

  5. Intellij Idea无法从Controller跳转到视图页面的解决方案

    解决方案: 第一步,确认配置了Spring支持,如下图: 一般情况下,配置完上面就可以正常导航了,但是今天要说的不是一般情况,否则也就不说了,如果经过第一步设置后,还是不能正常导航的同学,可以接着看第 ...

  6. 【python】choice函数

    来源:http://www.runoob.com/python/func-number-choice.html 描述 choice() 方法返回一个列表,元组或字符串的随机项. 语法 以下是 choi ...

  7. NEFU 2016省赛演练一 B题(递推)

    HK Problem:B Time Limit:2000ms Memory Limit:65535K Description yy is interested in numbers and yy nu ...

  8. Eclipse中android工程C++文件中出现的莫名其妙的错误

    大多数是std库相关的问题,例如 vector<int> v; v.push_back(23);//这句语法是没有错误的,但是每次执行Run As的时候就会报错 尝试1:在工程名右键-Cl ...

  9. TransactionScope使用说明

    TransactionScope是.Net Framework 2.0滞后,新增了一个名称空间.它的用途是为数据库访问提供了一个“轻量级”[区别于:SqlTransaction]的事物.使用之前必须添 ...

  10. ffmpeg 中添加264支持

    转自:http://blog.sina.com.cn/s/blog_513f4e8401011yuq.html ffmpeg 中带有264的解码,没有编码,需要添加x264: 参考百度上的“windo ...