【链接】 我是链接,点我呀:)
【题意】
【题解】
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
",ans);
return 0;
}