Portal: http://www.lydsy.com/JudgeOnline/problem.php?id=1001
The test instructions of the problem is actually to ask for a minimum cut, but because it is a graph, so add edge, both sides of the flow if the weight of the input, and then a dinic to seek the smallest cut.
But this problem seems to have a very high skill to do, you can make the minimum cut on the plane map to the shortest way on the dual graph to do, this can play a very obvious optimization effect. Now is not very clear, if later understand, will come back to update.
Dinic:
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <cstdlib>#include <cctype>#include <string>#include <iostream>#include <vector>#include <map>#include <queue>#include <ctime>using namespace STD;typedef Long LongLL;typedefpair<int,int> PII;#define PB push_back#define Lson l,m,rt<<1#define Rson m+1,r,rt<<1|1#define CALM (l+r) >>1Const intInf= (int)1e9+7;structee{intTo,cap,next; EE () {} EE (intTo,intCapintNext): To, Cap (CAP), next (next) {}}edge[6000010];intn,m,ecnt,st,ed,head[1000010];intd[1000010];inline intID (intXintY) {return(X-1) *m+y;}voidAddedge (intFromintTo,intCAP) {Edge[ecnt]=ee (To,cap,head[from]); head[from]=ecnt++; Edge[ecnt]=ee (From,cap,head[to]);//No direction diagramhead[to]=ecnt++;}BOOLBFS () { Queue<int>Q; Q.push (ST);memset(d,-1,sizeofD); d[st]=0; while(! Q.empty ()) {intS=q.front (); Q.pop (); for(intI=head[s];~i;i=edge[i].next) {intt=edge[i].to;if(edge[i].cap>0&&d[t]<0) {d[t]=d[s]+1; Q.push (t); } } }//printf ("d[ed]=%d\n", d[ed]); returnd[ed]>=0;}intDasointSintTintFlow) {if(s==t| | flow==0)returnFlowintans=0; for(intI=head[s];~i;i=edge[i].next) {EE &e=edge[i];if(e.cap>0&&d[e.to]==d[s]+1){intFf=dfs (E.to,t,min (Flow,e.cap));if(ff>0) {e.cap-=ff; edge[i^1].CAP+=FF; ANS+=FF; FLOW-=FF;if(!flow) Break; } } }if(!ans) d[s]=-1;returnAns;}voidDinic () {intans=0; while(BFS ()) {//printf ("here\n");Ans+=dfs (St,ed,inf);//printf ("%d\n", ans);}printf("%d\n", ans);}intMain () {//freopen ("/home/xt/code/acm/input.txt", "R", stdin); scanf("%d%d", &n,&m); st=1; Ed=id (n,m);memset(head,-1,sizeofHead); Ecnt=0; for(intI=1; i<=n;i++) { for(intj=1; j<m;j++) {intXscanf("%d", &x); Addedge (ID (I,J), ID (i,j+1), x); } } for(intI=1; i<n;i++) { for(intj=1; j<=m;j++) {intXscanf("%d", &x); Addedge (ID (I,J), ID (i+1, j), X); } } for(intI=1; i<n;i++) { for(intj=1; j<m;j++) {intXscanf("%d", &x); Addedge (ID (I,J), ID (i+1, j+1), x); }} dinic ();//printf ("[Run in%.1fs]\n", (double) clock ()/clocks_per_sec); return 0;}
BZOJ1001[BEIJING2006] Wolf Catch rabbit (no graph min cut)