Build all the edges and run the minimum cut, the title is minimal cut is not difficult to understand
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <queue>5 #defineM 10000096 using namespacestd;7 inthead[m],next[6*m],v[6*m],u[6*m],n,m,cnt=1, ans,d[m];8 voidJiaintA1,intA2,intA3)9 {Tencnt++; Onev[cnt]=A3; Au[cnt]=A2; -next[cnt]=HEAD[A1]; -head[a1]=CNT; the } - BOOLBFS () - { -memset (D,0,sizeof(d)); +queue<int>Q; -Q.push (1); +d[1]=1; A for(;!q.empty ();) at { - intnow=Q.front (); - Q.pop (); - for(intI=head[now];i;i=Next[i]) - if(v[i]&&!D[u[i]]) - { in Q.push (U[i]); -d[u[i]]=d[now]+1; to if(u[i]==n*m) + return 1; - } the } * return 0; $ }Panax Notoginseng intDinic (intXintf) - { the if(x==n*m) + returnF; A intrest=F,now; the for(intI=head[x];i;i=Next[i]) + if(v[i]&&d[u[i]]==d[x]+1&&rest) - { $now=dinic (U[i],min (rest,v[i)); $ if(!Now ) -d[u[i]]=0; -v[i]-=Now ; thev[i^1]+=Now ; -rest-=Now ;Wuyi } the returnF-rest; - } Wu intMain () - { Aboutscanf"%d%d",&n,&m); $ for(intI=1; i<=n;i++) - for(intj=1; j<m;j++) - { - intA1; Ascanf"%d",&A1); +Jia ((i-1) *m+j, (I-1) *m+j+1, A1); theJia ((i-1) *m+j+1, (I-1) *m+j,a1); - } $ for(intI=1; i<n;i++) the for(intj=1; j<=m;j++) the { the intA1; thescanf"%d",&A1); -Jia ((i-1) *m+j,i*m+j,a1); inJia (I*m+j, (i)1) *m+j,a1); the } the for(intI=1; i<n;i++) About for(intj=1; j<m;j++) the { the intA1; thescanf"%d",&A1); +Jia ((i-1) *m+j,i*m+j+1, A1); -Jia (i*m+j+1, (I-1) *m+j,a1); the }Bayi for(; BFS ();) theAns+=dinic (1,0x7fffffff); theprintf"%d\n", ans); - return 0; -}
Bzoj 1001: [BeiJing2006] Wolf catches rabbits