[Bzoj3875] [ahoi2014] The spfa of server guard games has a postactive motion regulation.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.