"bzoi2006" "Wolf Catch Rabbit" "Min Cut"

Source: Internet
Author: User

Description source:beijing2006 [BJOI2006]
Eight Chinese OJ on the subject link: 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.
Input
The first act N,m. Represents the size of the mesh, n,m are less than or equal to 1000. The next three parts of the first part of a total of N rows, the number of M-1 per row, representing the weight of the horizontal road. The second part of the total N-1 line, the number of M per row, indicating the weight of the longitudinal road. The third part of the total N-1 line, the number of M-1 per row, indicating the weighted value of the oblique road. Input file guaranteed not to exceed 10M
Output
Outputs an integer that represents the minimum number of wolves involved in an ambush.
Sample Input
3 4
5 6 4
4 3 1
7 5 3
5 6 7 8
8 7 6 5
5 5 5
6 6 6
Sample Output
14
The best way to do this is to run the shortest path after turning to the dual graph. The application of the maximum-minimum theorem in the competition of informatics is described in the paper "Two-pole connection"
Code:

#include <iostream>#include <cstdio>#include <cstring>using namespace STD;intcnt,point[1000001],dis[1000001],l[1000001],next[1000001],N,M,C,S,T,TT1;BOOLf[1000001];structuse{intSt,en,val;} b[2000000];voidAddintXintYintZ) {next[++cnt]=point[x];p oint[x]=cnt;    B[cnt].st=x;b[cnt].en=y;b[cnt].val=z;    Next[++cnt]=point[y];p oint[y]=cnt; B[cnt].st=y;b[cnt].en=x;b[cnt].val=z;}intSPFA (intXintY) {intH,t,u;memset(Dis,127/3,sizeof(dis)); dis[x]=0; h=0; t=1; l[t]=x; while(h<t) {U=l[++h]; for(intI=point[u];i;i=next[i])if(dis[b[i].en]>dis[u]+b[i].val&&u!=i) {dis[b[i].en]=dis[u]+b[i].val;if(!f[b[i].en]) {f[b[i].en]=true;                  L[++t]=b[i].en; }              }      }returnDis[y]>21000000?0:d Is[y]; }intMain () {Freopen ("Bjrabbit.in","R", stdin); Freopen ("Bjrabbit.out","W", stdout);scanf("%d%d", &n,&m); t=2*m*n-2*m-2*n+4; tt1=2* (M-1) * (n2); for(intI=1; i<=n;i++) for(intj=2; j<=m;j++) {scanf("%d", &c);inttemp=2* (M-1) * (I-2)+2* (J-1);if(i==1) Add (i+2* (J-1), t,c);if(i==n) Add (temp,s,c);if(i>1&&i<n) Add (temp,temp+2*m-1, c); } for(intI=2; i<=n;i++) for(intj=1; j<=m;j++) {inttemp=2* (M-1) * (I-2)+2* (J-1);scanf("%d", &c);if(j==1) Add (temp+2, s,c);if(j==m) Add (temp+1, t,c);if(j>1&AMP;&AMP;J&LT;M) Add (temp+1, temp+2, c); } for(intI=2; i<=n;i++) for(intj=2; j<=m;j++) {scanf("%d", &c);inttemp=2* (M-1) * (I-2)+2* (J-1); Add (temp,temp+1, c); }cout&LT;&LT;SPFA (s,t) <<endl;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"bzoi2006" "Wolf Catch Rabbit" "Min Cut"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.