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<>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)