Bzoj 1001 [BeiJing2006] Wolf catches rabbits

Source: Internet
Author: User

Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1001

The shortest-cut conversion is a classic problem.

The title looks like a minimum cut, and a look at the definition of cut and min cut:

Cut: For a graph, divide all vertices into two sets S and T=v-s, where the source point S is in the set S, and the meeting point T is in the set T. If you remove the "starting point in S, the end point in T", you cannot reach T from S. Such a set partition (S,T) is called a s-t cut, its capacity is the starting point in S, and the end point is the capacity of all sides in T.

Minimum cut: The smallest cut in the figure.

Maximum flow theorem by minimum cut:

For any network has a single origin and single destination node, the maximum possible flow from origin to destination E Quals the minimum cut value for all cuts in the network.

So you run the biggest stream and you come out? But V,e can reach 1e3, I know the fastest network flow algorithm ISAP all to O (v^2 E), so the network flow is not OK.

Such a diagram is called a s-t plan, so the graph is the shortest way to its dual graph.

Concrete view of Dong Zhou's "Two poles connecting"--analysis of the application of maximum minimum theorem in the competition of informatics

1 /*2 * Problem:bzoj 10013 * AUTHOR:SHJWUDP4 * Created time:2015/3/26 Thursday 16:36:425 * File name:233.cpp6 * state:accepted7 * Memo: Network flow, Shortest path8  */9#include <iostream>Ten#include <cstdio> One#include <cstring> A#include <algorithm> -#include <queue> -   the using namespacestd; -   - Const intinf=0x7f7f7f7f; -   + Const intmaxa=1e3+7; - Const intmaxb=maxa*maxa*2; + Const intmaxc=maxa*maxa*3; A   at structEdge { -     intV, NT; -     intW; - } EDGES[MAXC]; -   - intHEAD[MAXB], edgenum; in   - intN, M; to ints, t; +   - voidInitintN) { theMemset (Head,-1,sizeof(head[0]) * (n+3)); *edgenum=0; $ }Panax Notoginseng voidAddedge (intUintVintW) { -edges[edgenum].v=v; theedges[edgenum].w=W; +Edges[edgenum].nt=Head[u]; Ahead[u]=edgenum++; the } + namespaceDijkstra { -     structHeapnode { $         intd, u; $Heapnode (intDintu):d (d), U (u) {} -         BOOL operator< (Constheapnode& RHS)Const { -             returnD >RHS.D; the         } -     };Wuyi   the     intN; -     intd[maxa*maxa<<1]; Wu     BOOLdone[maxa*maxa<<1]; -     intGoints) { Aboutmemset (D,0x7f,sizeof(d[0]) * (n+3)); $memset (Done,0,sizeof(done[0]) * (n+3)); -d[s]=0; done[s]=1; -Priority_queueQ; -Q.push (Heapnode (0, s)); A          while(!Q.empty ()) { +Heapnode x=Q.top (); Q.pop (); the              for(intI=HEAD[X.U]; ~i; I=Edges[i].nt) { -edge& e=Edges[i]; $                 if(d[e.v]>d[x.u]+e.w) { thed[e.v]=d[x.u]+E.W; the                     if(!DONE[E.V]) { thedone[e.v]=1; the Q.push (Heapnode (d[e.v], e.v)); -                     } in                 } the             } the         } About         returnD[t]>=inf?0:d [t]; the     } the } the intMain () { + #ifndef Online_judge -Freopen ("inch","R", stdin); the     //freopen ("Out", "w", stdout);Bayi #endif the      while(~SCANF ("%d%d", &n, &M)) { theS= (n1) * (M-1)*2+1; T= (n1) * (M-1)*2+2; -Init (dijkstra::n= (n1) * (M-1)*2+2); -         intx; the          for(intI=0; i<n; i++) the              for(intj=0; j<m-1; J + +) { thescanf"%d", &x); theAddedge (i==0? s: ((i-1) * (M-1) +j) <<1|1, i==n-1? t: (I* (M-1) +j) <<1, x); -             } the          for(intI=0; i<n-1; i++) the              for(intj=0; j<m; J + +) { thescanf"%d", &x);94Addedge (j==m-1? s: (I* (M-1) +j) <<1|1, j==0? t: (I* (M-1) + (J-1)) <<1, x); the             } the          for(intI=0; i<n-1; i++) the              for(intj=0; j<m-1; J + +) {98scanf"%d", &x); AboutAddedge ((i* (M-1) +j) <<1, (i* (M-1) +j) <<1|1, x); -             }101          102printf"%d\n", Dijkstra::go (s));103     }104     return 0; the}
Bzoj 1001

Bzoj 1001 [BeiJing2006] Wolf catches rabbits

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.