"bzoj1179" Apio2009-atm

Source: Internet
Author: User

www.lydsy.com/JudgeOnline/problem.php?id=1179 (Topic link)

Test instructions: Give a graph, each node has a bit of power. Mark some points to find a path that can repeat through an edge, making the total point right and maximum. Repetition of a point can not be repeated to calculate the right.

Solution
Today's exam question, Dijkstra unfortunate GI rotten.
  Warning:dijkstra handle the longest road when there will be some bad situation, so don't use!!
Now that we can repeat some of the edges, once we pass through a certain ring, we can always run all the points on the ring, so it is obvious. First Tarjan the contraction point, so the whole diagram becomes a direction-free graph, run DP or SPFA the longest road can be.

Code:

bzoj1179#include<algorithm> #include <iostream> #include <cstdlib> #include <cstring># include<cstdio> #include <cmath> #include <queue> #define LL long long#define inf 2147483640#define Pi ACOs ( -1.0) #define FREE (a) freopen (a ".", "R", stdin), Freopen (a ". Out", "w", stdout); using namespace Std;const int maxn=    500010;struct data {int num,x;    friend BOOL Operator < (const data &AMP;X,CONST data &y) {return x.x<y.x; }};struct Edge {int to,next;} e[maxn<<1];struct E {int u,v;} Ee[maxn];int Dis[maxn],head[maxn],dfn[maxn],low[maxn],st[maxn],vis[maxn],pos[maxn],a[maxn],w[maxn],ll[maxn];int N,m,top,sum,cnt,s,ind,p;void link (int u,int v) {e[++cnt].to=v;e[cnt].next=head[u];head[u]=cnt;}    void Tarjan (int x) {dfn[x]=low[x]=++ind;    Vis[x]=1;    St[++top]=x;            for (int i=head[x];i;i=e[i].next) {if (!vis[e[i].to]) {Tarjan (e[i].to);        Low[x]=min (low[x],low[e[i].to]); } else if (!pos[e[i].to])           Low[x]=min (low[x],dfn[e[i].to]);        } if (Dfn[x]==low[x]) {sum++;        Int J;            do {j=st[top--];        POS[J]=SUM;W[SUM]+=A[J];    }while (st[top+1]!=x);    }}void Dijkstra () {priority_queue<data> q;    for (int i=1;i<=sum;i++) Dis[i]=-inf;    Data y,x= (data) {S,w[s]};    Q.push (x);d is[s]=w[s];        while (Q.size ()) {x=q.top (); Q.pop ();        if (Vis[x.num]) continue;        Vis[x.num]=1; for (int i=head[x.num];i;i=e[i].next) if (dis[e[i].to]<dis[x.num]+w[e[i].to]) {dis[e[i].to]=                Y.X=DIS[X.NUM]+W[E[I].TO];                y.num=e[i].to;            Q.push (y);    }}}void SPFA () {queue<int> q;    for (int i=1;i<=sum;i++) Dis[i]=-inf;    Q.push (S);d is[s]=w[s];        while (Q.size ()) {int X=q.front (); Q.pop ();        vis[x]=0; for (int i=head[x];i;i=e[i].next) if (dis[e[i].to]<dis[x]+w[e[i].to]) {dis[e[i].to]=dis[x]+w [e[I].TO];            if (!vis[e[i].to]) Q.push (e[i].to);    }}}int Main () {scanf ("%d%d", &n,&m);        for (int i=1;i<=m;i++) {scanf ("%d%d", &AMP;EE[I].U,&AMP;EE[I].V);    Link (EE[I].U,EE[I].V);    } for (int i=1;i<=n;i++) scanf ("%d", &a[i]);    scanf ("%d%d", &s,&p); Tarjan (S);    S=pos[s];        for (int x,i=1;i<=p;i++) {scanf ("%d", &x);    Ll[pos[x]]=1;    } for (int i=1;i<=n;i++) vis[i]=head[i]=0;    for (int i=1;i<=m;i++) if (POS[EE[I].U]!=POS[EE[I].V]) Link (pos[ee[i].u],pos[ee[i].v]);   Dijkstra ();    No SPFA ();    int ans=0;    for (int i=1;i<=sum;i++) if (Ll[i]) Ans=max (ans,dis[i]);    printf ("%d", ans); return 0;}

  

"bzoj1179" Apio2009-atm

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.