http://www.lydsy.com/JudgeOnline/problem.php?id=2127
For everyone to remember a point,
S->a [i][j]+ cost[a][b]/2 a->t Manager [i][j]+ COST[A][B]/2
S->a [i][j]+ cost[a][b]/2 a->t [i][j]+ Wen COST[A][B]/2
A<->b Li Cost[i][j]/2+ Wen cost[i][j]/2
1#include <algorithm>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <iostream>6 #defineINF 0x7fffffff7 intw[ the][ the][2],flow[200005],next[200005],first[200005],nodes,t,s;8 intHot200005],op[200005],dis[200005],cnt[200005],tot,m,n,id[ the][ the];9 intRead () {Ten intt=0, f=1;CharCh=GetChar (); One while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} A while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} - returnt*F; - } the voidInsertintXintYintz) { -tot++; -go[tot]=y; -next[tot]=First[x]; +first[x]=tot; -flow[tot]=Z; + } A voidAddintXintYintz) { atInsert (x, y, z); op[tot]=tot+1; -Insert (Y,x,0); op[tot]=tot-1; - } - voidADD2 (intXintYintz) { -Insert (x, y, z); op[tot]=tot+1; -Insert (y,x,z); op[tot]=tot-1; in } - intDfsintXintf) { to if(x==t)returnF; + intmn=nodes,sum=0; - for(intI=first[x];i;i=Next[i]) { the intPur=Go[i]; * if(flow[i]&&dis[pur]+1==Dis[x]) { $ intSave=dfs (Pur,std::min (fsum,flow[i]));Panax Notoginsengsum+=Save; -flow[i]-=Save; theflow[op[i]]+=Save; + if(sum==f| | Dis[s]>=nodes)returnsum; A } the if(Flow[i]) mn=std::min (Mn,dis[pur]); + } - if(sum==0){ $cnt[dis[x]]--; $ if(cnt[dis[x]]==0){ -dis[s]=nodes; -}Else{ thedis[x]=mn+1; -cnt[dis[x]]++;Wuyi } the } - returnsum; Wu } - intMain () { AboutN=read (); m=read (); $s=0; -t=n*m+1; -nodes=t+1; - intsz=0, ans=0; A for(intI=1; i<=n;i++) + for(intj=1; j<=m;j++) theid[i][j]=++sz; - for(intI=1; i<=n;i++) $ for(intj=1; j<=m;j++) thew[i][j][0]=read (), ans+=w[i][j][0],w[i][j][0]*=2; the for(intI=1; i<=n;i++) the for(intj=1; j<=m;j++) thew[i][j][1]=read (), ans+=w[i][j][1],w[i][j][1]*=2; - for(intI=1; i<=n-1; i++) in for(intj=1; j<=m;j++){ the intX=read (); ans+=x; thew[i][j][0]+=x;w[i+1][j][0]+=x; AboutADD2 (id[i][j],id[i+1][j],x); the } the for(intI=1; i<=n-1; i++) the for(intj=1; j<=m;j++){ + intX=read (); ans+=x; -w[i][j][1]+=x;w[i+1][j][1]+=x; theADD2 (id[i][j],id[i+1][j],x); Bayi } the for(intI=1; i<=n;i++) the for(intj=1; j<=m-1; j + +){ - intX=read (); ans+=x; -w[i][j][0]+=x;w[i][j+1][0]+=x; theADD2 (id[i][j],id[i][j+1],x); the } the for(intI=1; i<=n;i++) the for(intj=1; j<=m-1; j + +){ - intX=read (); ans+=x; thew[i][j][1]+=x;w[i][j+1][1]+=x; theADD2 (id[i][j],id[i][j+1],x); the }94 for(intI=1; i<=n;i++) the for(intj=1; j<=m;j++) theAdd (s,id[i][j],w[i][j][0]), add (id[i][j],t,w[i][j][1]); the intmnflow=0;98 while(Dis[s]<nodes) mnflow+=DFS (s,inf); Aboutprintf"%d\n", ans-mnflow/2); -}
Bzoj 2127 Happiness