"BZOJ-2502" clears the upper and lower bounds of the network stream (with the smallest stream in the nether)

Source: Internet
Author: User

2502: Clean up the snow lane time limit:10 Sec Memory limit:128 MB
submit:594 solved:318
[Submit] [Status] [Discuss] The description ski resort is located on several mountains 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. The first line of the input file contains an integer N(2 <= N<= 100) – The number of locations representing the ski slopes. The next NLine, Description 1~ NThe slope of the place of departure, section IThe first number of rows is mi(0 <= mi< N), followed by a total miInteger, separated by a space, each integer AIJDifferent, representing from the location IDown to the place AIJThe slopes. At least one ramp is connected to each location. The first line of the output file is an integer k– The minimum number of helicopters flown. Sample Input8
1 3
1 7
2 4 5
1 8
1 8
0
2 6 5
0
Sample Output4Hintsource

2011 Fujian Training

Solution

Minimum flow with a lower bound

It is easy to see that each side of the flow is at least 1, that is, the Nether is the only, the total flow is the smallest, it is clear that the nether is 1 of the minimum flow without upper bound or upper bound as inf

cannot be solved directly, consider the following:

Add a lower bound capacity of 1, an upper bound capacity inf for each edge;

s to the points of the edge, the lower bound 0, the upper bound INF, the points to the T-edge, the lower bound 0, the upper bound inf;

Finding the minimum flow is the answer, so consider the least-flow approach:

Adding Super Yuanhui becomes a Yuanhui viable stream, which requires a t-->s capacity of INF, which can be used to meet the lower bound traffic flowsum, but obviously not the

Get rid of the original s,t, then go through the flow, the final answer, that is, the minimum flow is Flowsum-flow

That's how you understand it:

When seeking the feasible flow, the resulting flow is not all on the direct path of (t,s), but also on the path between T-S, so it is clearly not the smallest

Then do again, it can be understood as the withdrawal of the flow, return as many streams as possible, because the nether is not to be returned, so the difference is the minimum flow

Code
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<vector>using namespacestd;intRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; Ch=GetChar ();}  while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}#defineMAXN 500#defineMAXM 1000010intN,m,ind[maxn],s,ss,t,tt;structedgenode{intTo,next,cap;} EDGE[MAXM];intHead[maxn],cnt=1;voidAddintUintVintW) {CNT++; Edge[cnt].to=v;edge[cnt].cap=w;edge[cnt].next=head[u]; head[u]=CNT;}voidInsertintUintVintW) {Add (u,v,w); Add (V,u,0);}intdis[maxn],que[maxn<<1],CUR[MAXN];BOOLBFs () { for(intI=0; i<=t; i++) dis[i]=-1; que[0]=s; dis[s]=0;intHe=0, Ta=1;  while(he<ta) {            intnow=que[he++];  for(intI=head[now]; I I=edge[i].next)if(Edge[i].cap && dis[edge[i].to]==-1) dis[edge[i].to]=dis[now]+1, que[ta++]=edge[i].to; }    returndis[t]!=-1;}intDfsintLocintLow ) {    if(loc==t)returnLow ; intW,used=0;  for(intI=cur[loc]; I I=edge[i].next)if(Edge[i].cap && dis[edge[i].to]==dis[loc]+1) {W=dfs (Edge[i].to,min (low-used,edge[i].cap)); Edge[i].cap-=w; edge[i^1].cap+=W; Used+=w;if(EDGE[I].CAP) cur[loc]=i; if(Used==low)returnLow ; }    if(!used) dis[loc]=-1; returnused;}#defineINF 0x7fffffffintDinic () {inttmp=0;  while(BFS ()) { for(intI=0; i<=t; i++) cur[i]=Head[i]; TMP+=DFS (S,inf); }    returntmp;}intA[MAXN][MAXN];intWork () { for(intI=1; i<=n; i++)         for(intj=1; j<=a[i][0]; J + +) Insert (I,a[i][j],inf), Ind[i]--, ind[a[i][j]]++; SS=n+1; tt=ss+1; s=tt+1; t=s+1;  for(intI=1; i<=n; i++) {insert (Ss,i,inf);              Insert (I,tt,inf); if(ind[i]>0) Insert (S,i,ind[i]); ElseInsert (i,t,-Ind[i]);     } insert (Tt,ss,inf); intflow=0, flowsum=0; Flow=Dinic (); Flowsum=Edge[cnt].cap; HEAD[SS]=Edge[head[ss]].next; HEAD[TT]=Edge[head[tt]].next;  for(intI=head[s]; I I=edge[i].next) Edge[i].cap=0, edge[i^1].cap=0;  for(intI=HEAD[T]; I I=edge[i].next) Edge[i].cap=0, edge[i^1].cap=0;  Insert (S,tt,inf);      Insert (Ss,t,inf); Flow=Dinic (); returnflowsum-Flow; }intMain () {n=read ();  for(intT,i=1; i<=n; i++) {a[i][0]=read ();  for(intj=1; j<=a[i][0]; J + +) A[i][j]=read (); } printf ("%d\n", work ()); return 0;}

"BZOJ-2502" clears the upper and lower bounds of the network stream (the smallest stream with the nether)

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.