bzoj1179: [Apio2009]Atm
2017-04-02 15:41
225 查看
传送门
对原图进行tarjan缩点后暴力dp一发水过。
对原图进行tarjan缩点后暴力dp一发水过。
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<cstdlib> #define ll long long #define inf 0x7fffffff #define N 500005 using namespace std; struct edge{int to,next;}e ,ed ; int head ,he ,f ,be ,v ,c ,dfn ,low ,q ,inq ; int n,m,s,p,tim,scc,top,cnt,ans; inline ll read(){ ll k=0,f=1; char ch=getchar(); for(;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1; for(;ch>='0'&&ch<='9';ch=getchar()) k=k*10+ch-'0'; return k*f; } void add(int u,int v){ e[++cnt].to=v; e[cnt].next=head[u]; head[u]=cnt; } void ins(int u,int v){ ed[++cnt].to=v; ed[cnt].next=he[u]; he[u]=cnt; } void tar(int x){ int now=0; dfn[x]=low[x]=++tim; q[++top]=x; inq[x]=1; for (int i=head[x];i;i=e[i].next) if (!dfn[e[i].to]){ tar(e[i].to); low[x]=min(low[x],low[e[i].to]); } else if (inq[e[i].to]) low[x]=min(low[x],dfn[e[i].to]); if (low[x]==dfn[x]){ scc++; while (now!=x){ now=q[top]; top--; be[now]=scc; v[scc]+=c[now]; inq[now]=0; } } } void rebuild(){ cnt=0; for (int i=1;i<=n;i++) for (int j=head[i];j;j=e[j].next) if (be[i]!=be[e[j].to]) ins(be[i],be[e[j].to]); } void spfa(){ int h=0,t=1; q[1]=be[s]; inq[q[1]]=1; f[q[1]]=v[q[1]]; while (h!=t){ h++; if (h>500000) h=1; int x=q[h]; inq[x]=0; for (int i=he[x];i;i=ed[i].next) if (f[x]+v[ed[i].to]>f[ed[i].to]){ f[ed[i].to]=f[x]+v[ed[i].to]; if (!inq[ed[i].to]){ inq[ed[i].to]=1; t++; if (t>500000) t=1; q[t]=ed[i].to; } } } } int main(){ n=read(); m=read(); for (int i=1;i<=m;i++){ int x,y; x=read(); y=read(); add(x,y); } for (int i=1;i<=n;i++) c[i]=read(); for (int i=1;i<=n;i++) if (!dfn[i]) tar(i); s=read(); p=read(); rebuild(); spfa(); for (int i=1;i<=p;i++){ int x=read(); if (f[be[x]]>ans) ans=f[be[x]]; } printf("%d",ans); }
相关文章推荐
- bzoj 1179 [Apio2009]Atm tarjan+最长路
- 【强联通分量缩点】【最短路】【spfa】bzoj1179 [Apio2009]Atm
- 【bzoj 1179】[Apio2009]Atm(Tarjan+spfa)
- bzoj1179 [Apio2009]Atm
- bzoj 1179: [Apio2009]Atm tarjan
- BZOJ 1179: [Apio2009]Atm(tarjan缩点+spfa)
- BZOJ1179 [Apio2009]Atm 【tarjan缩点】
- bzoj1179: [Apio2009]Atm
- BZOJ 1179: [Apio2009]Atm( tarjan + 最短路 )
- BZOJ 1179 APIO2009 ATM Tarjan+堆优化SPFA
- bzoj1179 [Apio2009]Atm
- BZOJ1179 [Apio2009]Atm 【tarjan缩点】
- BZOJ 1179 APIO 2009 Atm Tarjan+SPFA
- BZOJ_1179_[Apio2009]Atm_tarjan+spfa
- BZOJ 1179: [Apio2009]Atm Tarjan强连通分量缩点,SPFA,DP
- BZOJ 1179: [Apio2009]Atm【Trajan+最短路】
- [BZOJ1179] [Apio2009]Atm(强连通)
- [bzoj1179][Apio2009]Atm Tarjan+spfa
- 【BZOJ 1179】[Apio2009]Atm
- bzoj 1179: [Apio2009]Atm【tarjan+spfa】