BZOJ2661 (fee Flow)

Source: Internet
Author: User

Divide all the points into two, match the two points of the condition, X, y, the top, the flow is 1, the cost is-(x+y).

Do the minimum cost maximum flow, and the last ans div 2 can be.

Program bzoj2661;Constinf=2000000000;varLast,next,p,cost,cap,q:Array[0..1000000] ofLongint; Flag1,flag2:Array[0..10000] ofBoolean;    A,c,i,j,x,y,t,s,sum:longint; B:Array[0..1000000] ofLongint; PD:Array[0..10000] ofBoolean; D,ps:Array[0..10000] ofLongint;functiongcd (x,y:longint): Longint;begin  ify=0  ThenExit (x)ElseExit (GCD (y,xMoDy));End;procedureAdd (x,y,f,c:longint);beginInc (SUM); Next[sum]:=LAST[X]; last[x]:=sum; P[sum]:=y; Q[sum]:=x; Cost[sum]:=c; cap[sum]:=F;End;procedureADT (x,y,f,c:longint);beginAdd (x,y,f,c); Add (Y,x,0,-c);End;procedureSPFA;varI,j,l,r:longint;begin   fori:=0  toT Dod[i]:=INF;  Fillchar (Pd,sizeof (PD), false); L:=1; r:=1; Pd[s]:=true; b[1]:=s; d[s]:=0;  whileL<=r Do    beginI:=Last[b[l]];  whileI<>0  Do        begin          if(cap[i]>0) and(D[p[i]]>d[b[l]]+cost[i]) Then            beginD[p[i]]:=d[b[l]]+Cost[i]; Ps[p[i]]:=i; if  notPd[p[i]] Then                beginInc (R); B[R]:=P[i]; Pd[p[i]]:=true; End; End; I:=Next[i]; End; PD[B[L]]:=false;    Inc (L); End;End;procedureMINCMAXF;varX,i,j,cc,f,min:longint;beginF:=0; cc:=0;  whileTrue Do    beginSPFA; ifD[t]=inf Then        beginWriteln (fDiv 2,' ',-CCDiv 2);        Exit End; Min:=INF; X:=T;  whileX<>s Do        begin          ifCap[ps[x]]<min Thenmin:=Cap[ps[x]]; X:=Q[ps[x]]; End; X:=T;  whileX<>s Do        beginDec (cap[ps[x]],min); Inc (Cap[ps[x] XOR1],min); X:=Q[ps[x]]; End; CC:=cc+min*D[t]; F:=f+min; End;End;beginreadln (A,C); S:=0;  forI:=a toC Do     forJ:=a toC Do if(I&LT;&GT;J) Then      beginx:=trunc (sqrt (ABS (i*i-j*j)); ifX*x<>abs (I*I-J*J) Thencontinue; ifGCD (I,J) <>1  Thencontinue; Add (I,j+c,1,-(i+j)); End;  forI:=a toC DoAdd0I1,0);  forI:=a toC DoAdd (i+c,c*2+1,1,0); S:=0; t:=2*c+1; mincmaxf;End.
BZOJ2661

BZOJ2661 (fee Flow)

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.