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. Bulb Switcher

    There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...

  2. yum缓存配置

    引自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/09/2203916.html $ cat /etc/yum.conf    ...

  3. FastReport for delphi xe 安装步骤

    FastReport for delphi xe 安装步骤 1.先关闭DELPHI:2.下载后解压到一个目录,比如:D:FR:3.打开D:FR,运行recompile.exe ->点击" ...

  4. Lubuntu下配置Python开发环境

    安装完系统必须要做的几件事: 一.更新软件    (如果是通过最新版镜像安装,可无视此步骤)    1.选择速度比较快的源,默认的源速度不一定快.二.配置终端    1.设置终端背景,前景色,透明度  ...

  5. SQL单表查询

    --1,选择不猛30中的雇员 SELECT * FROM EMP WHERE DEPTNO = 30; --2,列出所有办事员的姓名,编号和部门 SELECT ENAME,EMPNO,DEPTNO F ...

  6. SimpleDataFormat格式

    public class SimpleDateFormat extends DateFormat SimpleDateFormat 是一个以国别敏感的方式格式化和分析数据的具体类. 它允许格式化 (d ...

  7. Java性能优化权威指南-读书笔记(五)-JVM性能调优-吞吐量

    吞吐量是指,应用程序的TPS: 每秒多少次事务,QPS: 每秒多少次查询等性能指标. 吞吐量调优就是减少垃圾收集器消耗的CPU周期数,从而将更多的CPU周期用于执行应用程序. CMS吞吐调优 CMS包 ...

  8. July 11th, Week 29th Monday, 2016

    I want to win a trophy, it's the most important. 我希望获得冠军奖杯,这是最重要的事情. Win a trophy, stand on the very ...

  9. typedef用法

    参考文章:http://www.cnblogs.com/shenlian/archive/2011/05/21/2053149.html

  10. struts2的标签中得到JSP脚本的变量值

    转自:http://www.cnblogs.com/modou/articles/1299024.html 大家先来看一段代码: <% int i=1; %> <s:property ...