BZOJ1927[SDOI2010] Star Racing

Source: Internet
Author: User

BZOJ1927[SDOI2010] Star Racing

Test instructions

The race is made up of n planets and M two-way interstellar routes, each of which has a different gravitational value. The competition requires riders to visit each of the N planets at exactly once, starting from a celestial body that does not have any route between the N planets. Racing Super Electric Donkey in high-speed sailing mode, sailing along the interstellar route, but only from each planet to the gravity of the larger planet. In the ability to burst mode, the Super Electric Donkey after a period of positioning, can instantly move to any planet. The shortest time to complete the game. n≤800,m≤15000

Exercises

Cost flow. Each point is split into X, y two points, the source is connected to each Y-point, the flow is 1, and the cost is the positioning time for the planet, which means passing through the planet directly. The source is then connected to each x point flow 1, the cost 0, each y point to the connecting edge, traffic 1, the cost 0. X and Y are connected by "interplanetary Route", which means from X point to Y point. We don't care where we go from here to the planet, we only consider that each planet can only pass once. Reflection: The mentally retarded at the beginning to understand any of the questions, and later found that they are capable of explosive mode needs to be restricted by gravity, not examining retired Qaq

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineMAXN 20007 #defineINF 0X3FFFFFFF8 using namespacestd;9 Ten structe{intF,t,c,w,n;}; E es[maxn* +];intESS,G[MAXN]; OneInlinevoidPeintFintTintCintW) { AEs[++ess]= (e) {f,t,c,w,g[f]}; g[f]=ess; Es[++ess]= (e) {t,f,0,-w,g[t]}; g[t]=ess; - } - voidInit () {ess=-1; memset (g,-1,sizeof(g));} the intD[MAXN],FR[MAXN];BOOLINQ[MAXN]; Queue <int>Q; - BOOLSPFA (intSintt) { -      while(!q.empty ()) Q.pop (); memset (INQ,0,sizeof(INQ)); memset (d,-1,sizeof(d)); -inq[s]=1; d[s]=0; Q.push (s); fr[s]=-1; +      while(!Q.empty ()) { -         intX=q.front (); Q.pop (); inq[x]=0; +          for(inti=g[x];i!=-1; i=es[i].n)if(es[i].c&& (d[es[i].t]==-1|| d[es[i].t]>d[x]+ES[I].W)) { AD[ES[I].T]=D[X]+ES[I].W; Fr[es[i].t]=i;if(!inq[es[i].t]) inq[es[i].t]=1, Q.push (es[i].t); at         } -     } -     returnd[t]!=-1; - } - intAdvancedintSintt) { -     intA=inf,c=0; in      for(inti=fr[t];i!=-1; I=FR[ES[I].F]) a=min (a,es[i].c); -      for(inti=fr[t];i!=-1; I=FR[ES[I].F]) es[i].c-=a,es[i^1].c+=a,c+= (A *ES[I].W); to     returnC; + } - intMaxflowmincost (intSintt) { the     intC=0; while(SPFA (s,t)) c+=advanced (s,t);returnC; * } $ intn,m,s,t;Panax Notoginseng intMain () { -scanf"%d%d", &n,&m); s=0; t=2*n+1; init (); theInc (I,1, N) {intA scanf"%d", &a); PE (S,I+N,1, a);} +Inc (I,1, m) {intA,b,c; scanf"%d%d%d", &a,&b,&c); PE (min (A, b), Max (A, b) +n,1, c);} AInc (I,1, n) PE (s,i,1,0), PE (I+N,T,1,0); theprintf"%d", Maxflowmincost (s,t));return 0; +}

20160527

BZOJ1927[SDOI2010] Star Racing

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.