Bzoj 1927 [Sdoi2010] Star Racing (minimum cost max flow)

Source: Internet
Author: User

1927: [Sdoi2010] Star Racing time limit:20 Sec Memory limit:259 MB
submit:1576 solved:954
[Submit] [Status] [Discuss] The Description10 Galaxy Racing competition is about to start again. As one of the biggest events in the Galaxy, the winner of this project is undoubtedly the dream of many people, and the one from Jason's Alpha star. The race is made up of N planets and M two-way interstellar routes, each of which has a different gravitational value. The competition asked the riders to start with a celestial body that had no route between the N planets, and to visit the N planets every time, and the first person to accomplish that goal was victorious. Because the format is very open, many people are driving strange, homemade cars to compete. The long-driving car called the Super Power Donkey, this is a gathering of the galaxy's most cutting-edge technology crystallization of the dream car. As the most high-tech products, the Super Electric Donkey has two modes of movement: high-speed sailing mode and ability burst mode. In high-speed mode, an ultra-electric donkey launches an antimatter engine that travels at high speed along the interstellar route at a speed of light. In the ability to burst mode, the Super Electric donkey out of the bondage of time and space, the use of super-ability to jump--after a period of positioning, it can instantly move to any planet. Days days wondering people wish, the day before the game, Super Electric Donkey in an ion storm unfortunate damage, function has some obstacles: in the use of high-speed navigation mode, only from each planet to the gravity of the larger planet, or the car will explode. Despite the problems of the beloved car, he still believes that he can win. He has found the smartest sage in the Galaxy-you, please arrange a match for him so that he can finish the game with the least amount of time. The first line of input is a two positive integer N, M. The second row N number A1~an, where AI represents the location time required to reach planet I using the ability burst mode. Next m line, 3 positive integers per line UI, VI, WI, indicates that there is an interstellar route between the planets numbered UI and VI that requires sailing WI time. The input data has been sorted by gravitational value, i.e. the small number of planets has a small gravitational value, and no two planets have the same gravitational value. Output contains only a positive integer, which indicates the minimum time required to complete the match. Sample Input3 3
1 100 100
2 1 10
1 3 1
2 3 1Sample Output AHINT

Description: Use the ability to burst mode to Planet 1, which takes time 1.
Then switch to high-speed sailing mode and sail to Planet 2, which takes time 10.
Then continue sailing to Planet 3 to complete the race, which takes time 1.
Although it looks better from Planet 1 to Planet 3 to Planet 2, we can't do that because
That will cause the super electric donkey to explode.

For 30% of data n≤20,m≤50;
For 70% of data n≤200,m≤4000;
For 100% of data n≤800, m≤15000. No number in the input data will exceed 106

Enter data to ensure that there is at most one fairway between any two planets, and there is no planet
Own fairway.

Source

First round Day2

Ideas

Minimum cost maximum flow.

Composition: Split Xi,yi. The connecting Edge (s,xi,1,0) (yi,t,1,0), if I and J have a length of W of the Edge is connected (XI,YJ,1,W). Note that for an "energy explosion" there is no need for each pair of points to be connected to each other, the time to teleport to each point is fixed, and if the value is W only requires a connecting edge (S,YI,1,W), the optimal choice between energy bursts and high speeds.

Code

1#include <cstdio>2#include <cstring>3#include <queue>4#include <vector>5 #definefor (A,B,C) for (int a= (b);a< (c); a++)6 using namespacestd;7 8typedefLong LongLL;9 Const intMAXN = -+Ten;Ten Const intINF =1e9; One  A structEdge {intU,v,cap,flow,cost; - }; - structzkw { the     intn,m,s,t; -     intD[MAXN],VIS[MAXN]; -Vector<edge>es; -vector<int>G[MAXN]; +      -     voidInitintN) { +          This->n=N; A es.clear (); at          for(intI=0; i<n;i++) g[i].clear (); -     } -     voidAddedge (intUintVintCapintCost ) { -Es.push_back (Edge) {u,v,cap,0, cost}); -Es.push_back (Edge) {v,u,0,0,-Cost }); -         intm=es.size (); inG[u].push_back (M-2), G[v].push_back (M-1); -     } to     BOOLSPFA () { +memset (Vis,0,sizeof(Vis)); -          for(intI=0; i<n;i++) d[i]=INF; thequeue<int>Q; *d[t]=0, vis[t]=1, Q.push (t); $          while(!Q.empty ()) {Panax Notoginseng             intU=q.front (); Q.pop (), vis[u]=0; -              for(intI=0; I<g[u].size (); i++) { theedge& e=Es[g[u][i]]; +                 intv=e.v; A                 if(es[g[u][i]^1].cap && d[v]>d[u]-e.cost) { thed[v]=d[u]-E.cost; +                     if(!Vis[v]) { -vis[v]=1; Q.push (v); $                     } $                 } -             } -         } the         returnd[s]!=INF; -     }Wuyi     intDfsintUinta,ll&Cost ) { thevis[u]=1;if(u==t)returnA; -         intUsed=0, W; Wu          for(intI=0; I<g[u].size (); i++) { -edge& e=Es[g[u][i]]; About             intv=e.v; $             if(D[v]==d[u]-e.cost && e.cap &&!)Vis[v]) { -W=dfs (V,min (A-used,e.cap), cost); -E.cap-=w, es[g[u][i]^1].cap+=W; -cost+=w*E.cost; AUsed+=w;if(used==a)returnA; +             } the         } -         returnused; $     } the     intMincost (intSintt,ll&Cost ) { the          This->s=s, This->t=T; the         intflow=0; cost=0; the          while(SPFA ()) { -vis[t]=1; in              while(Vis[t]) { thememset (Vis,0,sizeof(Vis)); theflow+=DFS (s,inf,cost); About             } the         } the         returnflow; the     } + } MC; -  the intn,m;Bayi  the intMain () { thescanf"%d%d",&n,&m); -Mc.init (n+n+2); -     ints=n+n,t=s+1, u,v,w; thefor (I,0, N) { thescanf"%d",&W); theMc. Addedge (S,i,1,0); theMc. Addedge (I+n,t,1,0); -Mc. Addedge (S,i+n,1, W); the     } thefor (I,0, M) { thescanf"%d%d%d",&u,&v,&W);94U--, v--;if(v<u) swap (u,v); theMc. Addedge (U,v+n,1, W); the     } the LL cost;98 MC. Mincost (s,t,cost); Aboutprintf"%lld", cost); -     return 0;101}

Bzoj 1927 [Sdoi2010] Star Racing (minimum cost max flow)

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.