Advertisement:
# Include <stdio. h> int main () {puts ("reprinted please specify the source [vmurder] Thank you"); puts ("url: blog.csdn.net/vmurder/article/details/41040735 ");}
Question:
First, a vertex can be split into multiple new vertices, thus having the foundation of the motion regulation on the graph.
That is, F [I] indicates the minimum cost of point I being eliminated. It can be updated by Split points.
However, this is post-efficient, so we use spfa to handle it.
Spfa post-effect dynamic regulation
Every time we update the dynamic value of point A, the dynamic value of several points may be updated.
That is, the points of vertex A can be split.
As a result, once the dynamic value of A is updated, the nodes will be added to the team.
All vertices should be queued at the beginning because they may be updated.
Code:
#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 201000#define M 2010000#define inf 0x3f3f3f3fusing namespace std;struct KSD{ int v,next;}e[M],E[M];int head[N],HEAD[N],cnt;inline void add(int u,int v){ e[++cnt].v=v; E[cnt].v=u; e[cnt].next=head[u]; E[cnt].next=HEAD[v]; HEAD[v]=head[u]=cnt;}long long A[N],dist[N];bool in[N];int n;queue<int>q;void spfa(){ while(!q.empty())q.pop(); int i,u,v; for(i=1;i<=n;i++)q.push(i),in[i]=1; while(!q.empty()) { u=q.front(),q.pop(),in[u]=0; long long temp=A[u]; for(i=head[u];i;i=e[i].next) temp+=dist[e[i].v]; if(temp>=dist[u])continue; dist[u]=temp; for(i=HEAD[u];i;i=E[i].next) if(!in[v=E[i].v])q.push(v),in[v]=1; }}int main(){ int i,j,k; int a,b,c; scanf("%d",&n); for(i=1;i<=n;i++) { cin>>A[i]>>dist[i]>>c; while(c--) { scanf("%d",&a); add(i,a); } } spfa(); cout<<dist[1]; return 0;}
[Bzoj3875] [ahoi2014] The spfa of server guard games has a postactive motion regulation.