Test instructions: Because of the insane destruction of nature, people realize that after about 2,300 years, the earth can no longer live, and then set up new green space on the moon so as to emigrate when needed. Surprisingly, the 2177 winter due to unknown reasons, the Earth's environment has been a chain collapse, the human must in the shortest possible time to move inland to the moon.
The existing n space stations are between the Earth and the Moon (ref. 1). n), M public transport spacecraft shuttling back and forth, each space station SI can accommodate unlimited people, each spacecraft pi can only accommodate the HPI people. For each spacecraft Pi, a series of space stations will be periodically docked (Si1,si2 ... Sir), such as: (1,3,4) means docking station 134134134.... It takes 1 for any spaceship to sail from any space station to another arbitrary space station. One can only ship or disembark when a spaceship docks (or the Earth or the moon) at a space station. The initial people were all on earth, and the spacecraft was all at the initial station (the spacecraft Pi was in Si1), with the goal of allowing all people to move all the way to the moon as soon as possible.
The first act of the file is three positive integers n (number of space stations), m (number of spacecraft), K (number of people on earth that need to be transported), of which 1<=m<=13, 1<=n<=20, 1<=k<=50.
Idea: Run the maximum flow by the time split point
Num[i,j] Represents the J point after I seconds
(I,J)--(I+1,J) even with unlimited flow
(i,x)--(i+1,y) with a flow of h[k], X, Y is a planet where the K spacecraft stay at the i,i+1 time, respectively.
Enumerate the answers and add edges, dinic
Note that the maximum flow after each run to restore the flow of reconstruction, changed for a long time did not change out
I'm still too simple.
By the way, 1999 years of official data, the second group is wrong, the correct answer is that 5,out is 7.
1 varHead,vet,next,len,dis,gap,fan,h,r,save:Array[0..100000] ofLongint;2A,b,num:Array[0.. the,0.. the] ofLongint;3 N,m,i,j,k,x,ans,tot,source,src,s:longint;4 5 procedureAdd (a,b,c:longint);6 begin7 Inc (TOT);8next[tot]:=Head[a];9vet[tot]:=b;Tenlen[tot]:=C; Onehead[a]:=tot; A End; - - functionmin (x,y:longint): Longint; the begin - ifX<y Thenexit (x); - exit (y); - End; + - functionDFS (u,aug:longint): Longint; + varE,v,val,flow,t:longint; A begin at ifU=src Thenexit (); -flow:=0; -E:=head[u]; val:=s-1; - whileE<>0 Do - begin -v:=Vet[e]; in ifLen[e]>0 Then - begin to ifdis[u]=dis[v]+1 Then + begin -T:=dfs (V,min (len[e],aug-flow)); thelen[e]:=len[e]-T; *len[fan[e]]:=len[fan[e]]+T; $flow:=flow+T;Panax Notoginseng ifDis[source]>=s Thenexit (flow); - ifAug=flow ThenBreak ; the End; +val:=min (val,dis[v]); A End; thee:=Next[e]; + End; - ifflow=0 Then $ begin $ Dec (Gap[dis[u]]); - ifgap[dis[u]]=0 Thendis[source]:=s; -dis[u]:=val+1; the Inc (Gap[dis[u]); - End;Wuyi exit (flow); the End; - Wu functionMaxflow:longint; - varAns:longint; About begin $Fillchar (dis,sizeof (DIS),0); -Fillchar (Gap,sizeof (GAP),0); -gap[0]:=s; -ans:=0; A whileDis[source]<s Doans:=ans+DFS (source,maxlongint); + exit (ans); the End; - $ begin theAssign (input,'codevs1034.in'); Reset (input); theAssign (output,'Codevs1034.out'); Rewrite (output); the readln (n,m,k); the fori:=0 to 101 Do - forj:=1 ton+2 Do in begin theInc (s); num[i,j]:=s; the End; About fori:=1 toM Do the begin the read (h[i]); Read (R[i]); the forj:=1 toR[i] Do + begin - read (a[i,j]); the ifa[i,j]=0 Thena[i,j]:=n+1;Bayi ifa[i,j]=-1 Thena[i,j]:=n+2; the End; thex:=1; B[i,0]:=a[i,1]; - forj:=1 to 101 Do - begin theInc (X);ifx=r[i]+1 Thenx:=1; theb[i,j]:=A[i,x]; the End; the - End; theans:=-1; thesource:=num[0, n+1]; the 94 fori:=0 to 101 Do the begin the forj:=1 toTot DoSAVE[J]:=LEN[J]; //It is extremely important to reconstruct the capacity of the edge thesrc:=num[i,n+2]; s:=src;98 ifMaxflow>=k Then beginAns:=i; BreakEnd; About forj:=1 toTot DoLEN[J]:=SAVE[J]; //It is extremely important to reconstruct the capacity of the edge - forj:=1 toM Do101 begin102fan[tot+1]:=tot+2;103fan[tot+2]:=tot+1;104Add (num[i,b[j,i]],num[i+1, b[j,i+1]],h[j]); theWriteln (I,' ', B[j,i],' ', i+1,' ', b[j,i+1],' ', H[j]);106Add (num[i+1, b[j,i+1]],num[i,b[j,i]],0);107Writeln (i+1,' ', b[j,i+1],' 'I' ', B[j,i],' ',0);108 End;109 forj:=1 ton+2 Do the begin111fan[tot+1]:=tot+2; thefan[tot+2]:=tot+1;113Add (num[i,j],num[i+1, j],maxlongint); theWriteln (I,' 'J' ', i+1,' 'J' ', maxlongint); theAdd (num[i+1, J],num[i,j],0); theWriteln (i+1,' 'J' 'I' 'J' ',0);117 End;118 Writeln;119 End; - ifAns>0 Thenwriteln (ANS)121 ElseWriteln (0);122//close (input);123//close (output);124 End.
"Codevs1034" Homeland (max Flow, split point)