Links: http://www.lydsy.com/JudgeOnline/problem.php?id=1001
Now the children's favorite "pleasant goat and ash too wolf", saying that the gray wolf catch the sheep, but the rabbit is still more in line, and now the rabbit is more stupid, they only two nest, now you as the Wolf King, facing the following a grid of terrain:
The upper-left corner is (n,m) and the lower-right corner is (n=4,m=5). There are three types of roads 1: (x, y) <==> (x+1,y) 2: (x, y) <==> (x,y+1) 3: (x, y) <==> (x+ 1,Y+1) The weight on the road indicates the maximum number of rabbits that can be passed on this road, and the road is non-direction. The upper-left and lower-right corners of the rabbit's two nests, at the beginning of all the rabbits gathered in the upper left corner of the nest, now they have to go to the lower right solution (n,m) in the nest, The Wolf King began to ambush the rabbits. Of course, for the sake of insurance, if a road up to the number of rabbits passed K, the Wolf King needs to arrange the same number of K wolf, in order to completely block the road, you need to help the Wolf King to arrange an ambush plan, so that the rabbit clean sweep under the premise of the number of wolves involved in the Because the wolf also to find pleasant sheep and sheep trouble. Idea: Dinic network flow incredibly past. It is said that the positive solution is what the dual graph
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <string>6#include <algorithm>7 intnext[7000005],first[7000005],go[7000005],tot,val[7000005];8 intdis[2000005],c[5000005],s,t,n,m,x,ans=0;9 Ten intStaintXinty) { One return(X-1) *m+y; A } - voidInsertintXintYintz) { -tot++; thego[tot]=y; -next[tot]=First[x]; -first[x]=tot; -val[tot]=Z; + -tot++; +go[tot]=x; Anext[tot]=First[y]; atfirst[y]=tot; -val[tot]=Z; - } - BOOLBFs () { - intnow,i; -memset (dis,-1,sizeofdis); in intH=0, t=1; -c[1]=S; todis[s]=0; + while(h<t) { -h++; thenow=C[h]; * for(intI=first[now];i;i=Next[i]) { $ intPur=Go[i];Panax Notoginseng if(val[i]&&dis[pur]<0){ -c[++t]=pur; thedis[pur]=dis[now]+1; + } A } the } + if(dis[t]==-1)return 0; - return 1; $ } $ intDfsintXintf) { - if(x==t)returnF; - intW,used=0; the for(intI=first[x];i;i=Next[i]) { - intPur=Go[i];Wuyi if(val[i]&&dis[pur]==dis[x]+1){ thew=f-used; -w=Dfs (Pur,std::min (w,val[i)); Wuval[i]-=W; -val[i+1]+=W; Aboutused+=W; $ if(used==f)returnF; - } - } - if(!used) dis[x]=-1; A returnused; + } the voidDinic () { - while(BFS ())) Ans+=dfs (1,0x7fffffff); $ } the intMain () { thescanf"%d%d",&n,&m); thes=1; t=STA (n,m); the for(intI=1; i<=n;i++) - for(intj=1; j<=m-1; j + +){ inscanf"%d",&x); theInsert (STA (i,j), STA (i,j+1), x); the } About for(intI=1; i<=n-1; i++) the for(intj=1; j<=m;j++){ thescanf"%d",&x); theInsert (STA (i,j), STA (i+1, J), X); + } - for(intI=1; i<=n-1; i++) the for(intj=1; j<=m-1; j + +){Bayiscanf"%d",&x); theInsert (STA (i,j), STA (i+1, j+1), x); the } - dinic (); -printf"%d", ans); the}
Bzoj 1001 Wolf Catch Rabbit