【BZOJ 1179】[Apio2009]Atm
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
tarjan强连通缩点一下。
然后把缩点之后,每个点的钱的数累加起来。
然后从S出发
开始一边做bfs一遍做dp.
最后输出有酒吧的点的dp值中的最大值。
【代码】
/*
n个点,m条有向边.
把有向图G的环进行缩点;
缩完之后的图存在vector <int> g[N]里面;
n变为缩完点之后的图的节点的个数了。
*/
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 5e5;//节点个数
vector <int> G[N+10],g[N+10];
int n,m,nn,tot = 0,top = 0,dfn[N+10],low[N+10],z[N+10],totn,in[N+10],value[N+10],value1[N+10];
int s,p,bo[N+10],bo1[N+10],dp[N+10];
int bh[N+10];
queue<int> dl;
void dfs(int x){
dfn[x] = low[x] = ++ tot;
z[++top] = x;
in[x] = 1;
int len = G[x].size();
rep1(i,0,len-1){
int y = G[x][i];
if (!dfn[y]){
dfs(y);
low[x] = min(low[x],low[y]);
}else
if (in[y] && dfn[y]<low[x]){
low[x] = dfn[y];
}
}
if (low[x]==dfn[x]){
int v = 0;
totn++;
while (v!=x){
v = z[top];
in[v] = 0;
bh[v] = totn;
top--;
}
}
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
tot = 0,totn = 0;
ri(n),ri(m);
rep1(i,1,m){
int x,y;
ri(x),ri(y);
G[x].pb(y);
}
rep1(i,1,n) ri(value[i]);
ri(s),ri(p);
rep1(i,1,p){
int x;
ri(x);
bo[x] = 1;
}
rep1(i,1,n)
if (dfn[i]==0)
dfs(i);
nn = totn;
rep1(i,1,n){
int len = G[i].size();
int xx = bh[i];
rep1(j,0,len-1){
int y = G[i][j];
int yy = bh[y];
if (xx!=yy)
g[xx].pb(yy);
}
}
rep1(i,1,n){
if (bo[i])
bo1[bh[i]] = 1;
value1[bh[i]]+=value[i];
}
memset(dp,255,sizeof dp);
dl.push(bh[s]);
dp[bh[s]] = value1[bh[s]];
while (!dl.empty()){
int x = dl.front();
dl.pop();
int len = g[x].size();
rep1(i,0,len-1){
int y = g[x][i];
if (dp[y]<dp[x]+value1[y]){
dp[y] = dp[x] + value1[y];
dl.push(y);
}
}
}
int ans = 0;
rep1(i,1,nn)
if (bo1[i]){
ans = max(ans,dp[i]);
}
printf("%d\n",ans);
return 0;
}
【BZOJ 1179】[Apio2009]Atm的更多相关文章
- 【BZOJ 1177】 [Apio2009]Oil
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如上图. 显然如果三个正方形.只可能是上面的情况. 则可以处理一下左上角.右上角.左下角.右下角的前缀最大正方形(dp),以及以某一 ...
- 【BZOJ 1150】 1150: [CTSC2007]数据备份Backup (贪心+优先队列+双向链表)
1150: [CTSC2007]数据备份Backup Description 你在一家 IT 公司为大型写字楼或办公楼(offices)的计算机数据做备份.然而数据备份的工作是枯燥乏味 的,因此你想设 ...
- Kruskal算法及其类似原理的应用——【BZOJ 3654】tree&&【BZOJ 3624】[Apio2008]免费道路
首先让我们来介绍Krukal算法,他是一种用来求解最小生成树问题的算法,首先把边按边权排序,然后贪心得从最小开始往大里取,只要那个边的两端点暂时还没有在一个联通块里,我们就把他相连,只要这个图里存在最 ...
- 【BZOJ 2957】楼房重建&&Codechef COT5 Count on a Treap&&【NOIP模拟赛】Weed 线段树的分治维护
线段树是一种作用于静态区间上的数据结构,可以高效查询连续区间和单点,类似于一种静态的分治.他最迷人的地方在于“lazy标记”,对于lazy标记一般随我们从父区间进入子区间而下传,最终给到叶子节点,但还 ...
- LCA 【bzoj 4281】 [ONTAK2015]Związek Harcerstwa Bajtockiego
[bzoj 4281] [ONTAK2015]Związek Harcerstwa Bajtockiego Description 给定一棵有n个点的无根树,相邻的点之间的距离为1,一开始你位于m点. ...
- 【Tarjan】+【SPFA】APIO2009 Atm
一.算法介绍 tarjan——求解有向图强连通分量.这个算法在本人的一篇blog中有介绍,这里就不赘述了.贴上介绍tarjan的的blog链接:http://www.cnblogs.com/Maki- ...
- 【BZOJ 1191】 [Apio2010]特别行动队 (斜率优化)
dsy1911: [Apio2010]特别行动队 [题目描述] 有n个数,分成连续的若干段,每段的分数为a*x^2+b*x+c(a,b,c是给出的常数),其中x为该段的各个数的和.求如何分才能使得各个 ...
- 【BZOJ 1096】 [ZJOI2007]仓库建设 (斜率优化)
1096: [ZJOI2007]仓库建设 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3940 Solved: 1736 Description ...
- 【BZOJ 2132】圈地计划 && 【7.22Test】计划
两种版本的题面 Description 最近房地产商GDOI(Group of Dumbbells Or Idiots)从NOI(Nuts Old Idiots)手中得到了一块开发土地.据了解,这块土 ...
随机推荐
- leetcode小题解析
描述Given an array of integers, return indices of the two numbers such that they add up to a specific ...
- 2019-03-28 SQL Server Pivot
--现在我们是用PIVOT函数将列[WEEK]的行值转换为列,并使用聚合函数Count(TotalPrice)来统计每一个Week列在转换前有多少行数据,语句如下所示 select * from Sh ...
- ASP.NET-HttpPostedFileBase file为null的问题
MVC使用Ajax.BeginForm上传图片时HttpPostedFileBase file为null,Request.Files获取不到文件,问题分析是页面中存在jquery.unobtrusiv ...
- ASP.NET-后台cookie与前台JQUERY解析cookie
在controller中给cookie赋值 HttpCookie cookie =newHttpCookie("pageInfo"); cookie["page_inde ...
- WinServer-IIS-请求筛选
这个实在太多了,可以比较好的控制网站的访问 来自为知笔记(Wiz)
- Android高级控件(一)——ListView绑定CheckBox实现全选,添加和删除等功能
Android高级控件(一)--ListView绑定CheckBox实现全选,添加和删除等功能 这个控件还是挺复杂的.也是项目中应该算是比較经常使用的了,所以写了一个小Demo来讲讲,主要是自己定义a ...
- MapReduce运行流程具体解释
在hadoop中.每一个mapreduce任务都会被初始化为一个Job. 每一个Job又能够分为两个阶段:map阶段和reduce阶段.这两个阶段分别用两个函数来表示,即map函数和reduce函数. ...
- HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException
HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException type ...
- ZOJ 3690 Choosing number(dp矩阵优化)
Choosing number Time Limit: 2 Seconds Memory Limit: 65536 KB There are n people standing in a r ...
- hashmap 循环取出全部值 取出特定的值 两种方法
//第一种 Iterator menus = menu.iterator(); while(menus.hasNext()) { Map userMap = (Map) menus.next(); S ...