Implementation function: Ibid
The program is still beautiful, although a little longer than the adjacency matrix, but it does not matter this is inevitable, but the more important one must be-speed will be a qualitative leap ^_^ (this point pointer slightly made some innovative--anti pointer, which points to the current arc of the reverse arc, Facilitate the operation of the path augmentation, compared to the non-recursive inside to use an OP function to find out is already much stronger!!! )
1 type2Point=^node;3Node=Record4 G,w:longint;5 Anti,next:point;6 End;7 var8 I,j,k,l,m,n,ans,s,t:longint;9A:Array[0..10000] ofPoint ;TenD,DV:Array[0..10000] ofLongint; One functionmin (x,y:longint): Longint;inline; A begin - ifX<y ThenMin:=xElsemin:=y; - End; the procedureAdd (x,y,z:longint); inline; - varP:point; - begin -New (p);p ^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p; +New (p);p ^.g:=x;p^.w:=0;p ^.next:=a[y];a[y]:=p; -a[y]^.anti:=a[x];a[x]^.anti:=A[y]; + End; A functionDFS (x,flow:longint): Longint;inline; at varI,j,k,l:longint;p:point; - begin - ifX=t Thenexit (flow); -dfs:=0;p: =A[x]; - whileP<>Nil Do - begin in if(p^.w>0) and(D[x]= (d[p^.g]+1)) Then - begin toK:=dfs (P^.g,min (flow-dfs,p^.w)); + Dec (p^.w,k); - Inc (P^.ANTI^.W,K); the Inc (DFS,K); * ifDfs=flow Thenexit; $ End;Panax Notoginsengp:=P^.next; - End; the ifD[s]=n Thenexit; + Dec (dv[d[x]]); A ifdv[d[x]]=0 Thend[s]:=N; the Inc (D[x]); Inc (Dv[d[x]); + End; - begin $ readln (n,m,s,t); $ fori:=1 toN Doa[i]:=Nil; - fori:=1 toM Do - begin the readln (j,k,l); - Add (j,k,l);Wuyi End; theFillchar (d,sizeof (d),0); -Fillchar (Dv,sizeof (DV),0); Wudv[0]:=n;ans:=0; - whileD[s]<n DoInc (Ans,dfs (S,maxlongint)); About writeln (ans); $ End.
Algorithm template--SAP Network maximum stream 3 (recursive + adjacency table)