ZOJ2770 Burn the Linked Camp (differential constraint system)

Source: Internet
Author: User

Interval and be sure to contact the prefix and.

    1. This problem, the prefix and as a point, from S0 to SN;
    2. For each camp I capacity capi, there is such a relationship si-si-1<=capi;
    3. For each interval of evaluation i,j,k, there is sj-si-1>=k, i.e. si-1-sJ<=k;
    4. Next is the edge, for v<=u+w from u to v Lian Quan W, the super-source to n+1 points of the edge 0.
    5. finally run SPFA, if there is negative ring there is no solution; and there is a solution, the answer is in D[SN], but because the title of the prefix and the non-negative integer and the minimum requirements, it is necessary to let all the numbers in D at the same time with the appropriate number to get another real solution.
1#include <cstdio>2#include <cstring>3#include <queue>4#include <algorithm>5 using namespacestd;6 #defineINF (1&LT;&LT;30)7 #defineMAXN 11118 #defineMAXM 222229 Ten structedge{ One     intV,cost,next; A }EDGE[MAXM]; - intHead[maxn],ne; - voidAddedge (intUintVintCost ) { theEdge[ne].v=v; Edge[ne].cost=cost; edge[ne].next=Head[u]; -head[u]=ne++; - } -  + intN,M,D[MAXN],CNT[MAXN]; - BOOLVIS[MAXN]; + BOOLSPFA () { A      for(intI=0; i<=n; ++i) { atvis[i]=0; cnt[i]=0; d[i]=INF; -     } -vis[n+1]=1; cnt[n+1]=1; d[n+1]=0; -queue<int>que; -Que.push (n+1); -      while(!Que.empty ()) { in         intu=Que.front (); Que.pop (); -         if(cnt[u]>n+1)return 0; to          for(intI=head[u]; i!=-1; I=Edge[i].next) { +             intv=edge[i].v; -             if(d[v]>d[u]+edge[i].cost) { thed[v]=d[u]+Edge[i].cost; *                 if(!Vis[v]) { $vis[v]=1;Panax Notoginseng++Cnt[v]; - Que.push (v); the                 } +             } A         } thevis[u]=0; +     } -     return 1; $ } $ intMain () { -     intA,B,C,CAP[MAXN]; -      while(~SCANF ("%d%d",&n,&m)) { the          for(intI=1; i<=n; ++i) scanf ("%d", cap+i); - Wuyimemset (head,-1,sizeof(head)); theNe=0; -          for(intI=1; i<=n; ++i) Addedge (i-1, I,cap[i]); Wu          for(intI=0; i<=n; ++i) Addedge (n+1I0); -          while(m--){ Aboutscanf"%d%d%d",&a,&b,&c); $Addedge (b,a-1,-c); -         } -         if(SPFA ()) { -             inttmp=INF; A              for(intI=0; i<=n; ++i) tmp=min (tmp,d[i]); +             if(tmp<0) d[n]-=tmp; theprintf"%d\n", D[n]); -}ElsePuts"Bad estimations"); $     } the     return 0; the}

ZOJ2770 Burn the Linked Camp (differential constraint system)

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.