XWW is a man of great influence, he has a lot of followers. These followers all want to join XWW to teach XWW to be a believer. But this is not easy, need to pass XWW examination.
XWW gives you a problem: Xww gives you a n*n positive real number matrix A to satisfy the xww nature.
The matrix that is called a n*n satisfies xww when and only if: (1) a[n][n]=0; (2) The last element of each row in the matrix equals the number of N-1 before the row, and (3) The last element of each column in the matrix equals the number of N-1 before the column.
Now you want to take the number of a in the rounding operation (can be rounding or rounding), so that the final a matrix still satisfies the xww nature. The XWW also requires the sum of the elements in a to be as large as possible.
First it is easy to see that this is a network flow problem with the upper bound ...
Source point to a point edge representing each row, representing the point of each column to the meeting point edge
Each row is connected to each column, and the edge is the same as the previous no Yuanhui feasible flow
And then because of the maximum flow, the two-point answer
Every time you connect a lower bound to mid from t→s
Here's the problem. What does the final output have to do with the final mid?
Let's consider what the traffic on this chart stands for.
The side that we even represent At first, the lower limit is considered as the value of the fluctuation.
But it's actually very simple, the value of each lattice.
The answer to the final output is the value of the entire graph.
Each point is counted at its own position, at the end of the line, and at the end of the column
So multiply the 3 output to get it.
Because the INF was set too small wa two times ...
Program zoj2314;ConstMAXN =2100; MAXM =800010; INF =100000007;varfa,next,ter,w,rec,flow:array[-1.. Maxm]of Longint; link,dis,opt,inp:array[-1.. Maxn]of Longint; vis:array[-1.. Maxn]of Boolean; N,m,e,tt,test,i,s,t,x,y,l,r,j,mid,sum,lx,rx,ans:longint; a:array[-1.. maxn,-1.. Maxn]of extended;function min (a,b:longint): Longint;beginifA<b then exit (a)Elseexit (b); end;function Spfa:boolean;varHead,tail,x,j:longint;begin Fillchar (Vis,sizeof(VIS),true); Fillchar (DIS,sizeof(DIS), the); Head:=0; tail:=1; opt[1]:=s;vis[s]:=false;d is[s]:=0; whileHead<>tail DoBegin head:= (head+1) mod maxn; X:=opt[head];j:=Link[x]; whileJ<>0 Dobeginif(dis[x]+1<DIS[TER[J]]) and (w[j]>0) THEN BEGIN DIS[TER[J]]:=dis[x]+1; ifVis[ter[j]] then BEGIN VIS[TER[J]]:=false; Tail:= (tail+1) mod maxn; Opt[tail]:=Ter[j]; End End J:=Next[j]; End VIS[X]:=true; End ifdis[t]<>dis[t+1] Then exit (true)ElseExitfalse); end;function dfs (p,sum:longint): Longint;vartem,j,x:longint;begin tem:=0; ifp=T then exit (sum); J:=Link[p]; whileJ<>0 Dobeginif(dis[ter[j]]=dis[p]+1) and (w[j]>0Then begin x:=dfs (Ter[j],min (sum-tem,w[j])); Inc (TEM,X);d EC (W[J],X); Inc (W[REC[J]],X); ifrec[j]=j+1Then Inc (FLOW[FA[J]],X)ElseDec (flow[fa[rec[j]]],x); iftem=sum then exit (sum); End J:=Next[j]; End Exit (TEM); end;procedure Add (X,y,z:longint); Begin Inc (E); Ter[e]:=y;next[e]:=link[x];link[x]:=e;w[e]:=z;rec[e]:=e+1; Inc (E); Ter[e]:=x;next[e]:=link[y];link[y]:=e;w[e]:=0; rec[e]:=e-1; end;function Jud:boolean;varJ:longint;begin J:=Link[s]; whileJ<>0 DobeginifW[j]>0Then Exit (false); J:=Next[j]; End Exit (true); end;function Solve:boolean;vari,sum:longint;begin sum:=0; whileSpfa DoInc (Sum,dfs (s),1000000007)); if(not Jud) then exit (false)ElseExittrue); End;begin readln (n); ans:=0; fori:=1to n Dobegin forj:=1to n Dobegin Read (A[i,j]); Inc (Ans,trunc (A[I,J)); end; READLN; End Lx:=0; rx:=10000000007; sum:=-1; whileLx<=rx Dobegin Mid:= (LX+RX) >>1; Fillchar (Next,sizeof(next),0); Fillchar (Link,sizeof(link),0); Fillchar (INP,sizeof(INP),0); E:=0; s:=0; t:=2*n+1; fori:=1to n1 Dobegin L:=trunc (A[i,n]); ifA[i,n]<>l then add (s,i,1); Dec (INP[S],L); Inc (INP[I],L); L:=trunc (A[n,i]); ifA[n,i]<>l then add (n+i,t,1); Dec (inp[n+I],l); Inc (INP[T],L); End fori:=1to n1 Do forj:=1to n1 Dobegin L:=trunc (A[i,j]); ifA[i,j]<>l then add (i,n+j,1); Dec (INP[I],L); Inc (Inp[n+j],l); End Add (T,s,inf); Inc (INP[S],MID);d EC (INP[T],MID); Dec (s); Inc (T); fori:=s+1to T1 Do ifInp[i]>0Then add (S,i,inp[i])Else ifinp[i]<0Then add (i,t,-Inp[i]); ifSolve then begin Sum:=mid; Lx:=mid+1EndElserx:=mid-1; End Writeln (Sum*3); end.
[BZOJ3698] XWW Problem Solving Report | Upper and lower bounds network flow | with Yuanhui maximum flow