[BZOJ2502] to clean up the snow Road Problem Solving Report | The minimum flow below the bounds

Source: Internet
Author: User

The
ski slopes are located on several hills in the northwestern part of FJ Province. from the aerial view, the ski slopes can be seen as a directed, non-circular map, each arc represents a slope (that is, the snow path), the direction of the arc represents the direction of the slope descent. Your team is responsible for cleaning the slopes regularly every week. You have a helicopter, and each flight can take one person from headquarters to a location on the ski slopes before flying back to headquarters. From the point of landing, the man could glide down the slope and clean up the snow path he had passed. as the cost of each flight is fixed, in order to minimize the cost, you want to know how to use the minimum number of flights to complete the task of cleaning the snow.
test instructions is given a DAG, which asks for the minimum number of path bars at least once for each edge to cover all edges At This point the answer is 4
It is easy to see that the minimum flow is calculated once on each side that is , the minimum flow with the nether The workaround is simple: for one (x, y) an edge with a capacity of 1 from X to Y and a cost of-inf, depending on the nature of the maximum flow at the minimum cost we can see that this side is obviously going to flow. then, given that each edge passes more than once , it is connected from X to Y with a capacity of INF, with a cost of 0 side source point to all point edges with 0 degrees, all edges with a 0 edge to the sink point but obviously the maximum flow is not to be finished, when to stop it? Each augmentation must be augmented by a path with the least cost.When there is still an edge in the picture, there is a cost for the-inf in the path that has been graced. when all the edges in the diagram pass, the cost of the augmented path is 0 .It 's time to stop.    In addition, a question was considered afterwards: Why is this guaranteed to be the minimum flow? each time the augmentation then the mark feels just a simulation but it will be found that each Benquan value is-inf, and the minimum cost maximum flow combination make sure that every path you pick fills up as many sides as you can.The existence of reverse arc also makes the correctness of the result more guaranteed .
Program XJT7;ConstMAXN = the; MAXM =100010; INF =10000000007;varN,m,e,s,t,x,y:int64;    I,j:longint; fa,next,link,w,cost,rec,son:array[-1..    Maxm]of Int64; dis,opt,pos,pre,b,lea:array[-1..    Maxn]of Int64; vis:array[-1.. Maxn]of boolean;function min (a,b:int64): Int64;beginifA<b then exit (a)Elseexit (b); end;procedure Add (X,y,z,cst:int64); Begin Inc (E); Fa[e]:=y;next[e]:=link[x];link[x]:=e;w[e]:=z;cost[e]:=cst;rec[e]:=e+1; son[e]:=x; Inc (E); Fa[e]:=x;next[e]:=link[y];link[y]:=e;w[e]:=0; cost[e]:=-cst;rec[e]:=e-1; son[e]:=y;end;function Spfa:boolean;varHead,tail,x,j:int64;begin Fillchar (Vis,sizeof(VIS),true); Fillchar (DIS,sizeof(DIS), the); Head:=0; tail:=1; opt[1]:=s;dis[s]:=0; vis[s]:=false;  whileHead<>tail DoBegin head:= (head+1) mod maxn; X:=opt[head];j:=Link[x];  whileJ<>0  Dobeginif(w[j]>0) and (dis[x]+cost[j]<Dis[fa[j]] then BEGIN DIS[FA[J]]:=DIS[X]+COST[J];p re[fa[j]]:=J; ifVis[fa[j]] then BEGIN VIS[FA[J]]:=false; Tail:= (tail+1) mod maxn; Opt[tail]:=Fa[j];            End            End J:=Next[j];        End VIS[X]:=true;    End ifdis[t]<>dis[t+1] Then exit (true); Exit (false); end;procedure MCMF;varsum,u,mn,ans:int64;begin ans:=0;  whileSpfa DoBegin sum:=0; U:=t;mn:=INF;  whileU<>s Dobegin MN:=min (Mn,w[pre[u]]); U:=Son[pre[u]];        End U:=T;  whileU<>s DoBegin Inc (SUM,MN*Cost[pre[u]]);            Dec (W[PRE[U]],MN); Inc (W[REC[PRE[U]]],MN); U:=Son[pre[u]];        End ifSum>0Then Break;    Inc (ANS,MN);    End Writeln (ans); End;begin//assign (input, ' xjt7.in '); reset (input);READLN (n); Fillchar (b,sizeof(b),0);  fori:=1to n Dobegin Read (Lea[i]);  forj:=1To Lea[i] Dobegin read (y); Add (I,y,1,-inf); Add (I,y,inf,0);        Inc (B[y]);        End    READLN;    End S:=0; t:=n+1;  fori:=1to n Do ifb[i]=0Then add (S,i,inf,1);  fori:=1to n Do iflea[i]=0Then add (I,t,inf,1); Mcmf;end.

[BZOJ2502] to clean up the snow Road Problem Solving Report | The minimum flow below the bounds

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.