JLOI2010 Championship Survey min cut

Source: Internet
Author: User

varb,f:Array[0..100000] ofLongint;  S,t,i,j,n,m,x,y:longint; L,h:Array[0.. +] ofLongint; A:Array[0.. +,0.. +] ofLongint;procedureBFS;varI,head,tail,x,y:longint;beginFillchar (b,sizeof (b),0);  Fillchar (H,sizeof (h), $7f); H[T]:=0; Head:=1; tail:=1; b[1]:=T;  whileHead<=tail Do    beginx:=B[head];  fori:=1  toN Do        if(a[i,x]>0) and(h[i]>=n) Then          beginInc (tail); B[tail]:=i; H[i]:=h[x]+1; End;    Inc (head); End;End;functionDFS (now,inl:longint): Longint;varI,outl:longint;begin  ifNow=t Thenexit (INL); DFS:=0;  fori:=l[now]+1  toN Do    if(l[i]<n) and(a[now,i]>0) and(h[now]=h[i]+1) Then      begin        ifA[now,i]>inl Thenoutl:=dfs (I,INL)Elseoutl:=DFS (I,a[now,i]); INL:=inl-outl; DFS:=dfs+outl; A[now,i]:=a[now,i]-outl; A[i,now]:=a[i,now]+outl; ifInl=0  ThenBreak ;      Inc (L[now]); End;End;functionDinic:longint;varSum:longint;beginsum:=0;  whileH[s]<n Do    beginFillchar (l,sizeof (l),0); Sum:=sum+DFS (S,maxlongint);    BFs End; Exit (sum);End;beginreadln (n,m);  fori:=1  toN Doread (f[i]);  fori:=1  toN Do    iff[i]=0  Thena[1, i+1]:=1 Elsea[i+1, n+2]:=1;  fori:=1  toM Do    beginreadln (x, y); A[x+1, y+1]:=1; A[y+1, x+1]:=1; End; S:=1; T:=n+2; N:=n+2; Writeln (dinic);End.

JLOI2010 Championship Survey min cut

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.