Bzoj 1001 Wolf Catch rabbit Dual diagram +SPFA

Source: Internet
Author: User

The problem is to find the smallest cut of the graph, that is, the maximum flow. But because there are too many sides, the maximum flow algorithm is T, so the maximum flow algorithm cannot be used.

Because this is a plan, it is a special technique to find the minimum cut of a plane graph and then find the shortest path to the dual graph. Treat each face as a point the weight of the edge between the f*,f* is the weight of the edge that crosses the edge of the f* with the previous point F. (not clear, everyone can read other blogs, speak very well)

In this way, a dual graph g* is built, thus the g* of the dual graph corresponds to a cut of the original G. So the shortest way to find g* is equal to the minimum cut of G.

After encountering the plan to find the smallest cut it will be transformed into a dual graph to find the shortest way, so that time efficiency will be greatly improved.

88732 KB 3572 Ms C++/edit 2195 B
1#include <queue>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 intpoint[2000103],next[6000103],v[6000103],c[6000103];7 intCnt=0, s,t,n,m,dist[2000103];8 BOOLvis[2000103];9queue<int>Q;Ten voidInsect (intXintYintz) One{Cnt++;next[cnt]=point[x];p oint[x]=cnt;v[cnt]=y;c[cnt]=Z;} A voidin1 () - { -     intI,j,num; the      for(j=1; j<m;++j) -     { -scanf"%d",&num); -Insect (j*2, t,num); +Insect (t,j*2, num); -     } +      for(i=2; i<n;++i) A       for(j=1; j<m;++j) at      { -scanf"%d",&num); -Insect ((I-1) * (M-1)*2+j*2, (I-1) * (M-1)*2+j*2-m*2+1, num); -Insect ((I-1) * (M-1)*2+j*2-m*2+1, (I-1) * (M-1)*2+j*2, num); -      } -      for(j=1; j<m;++j) in     { -scanf"%d",&num); toInsect (s, (n2)*2* (M-1) +j*2-1, num); +Insect ((n2)*2* (M-1) +j*2-1, s,num); -     } the } * voidin2 () $ {Panax Notoginseng     inti,j,num,xx; -      for(i=1; i<n;++i) the     { +scanf"%d", &num); xx= (I-1) * (M-1)*2+1; A insect (s,xx,num); the insect (xx,s,num); +          for(j=2; j<m;++j) -         { $scanf"%d", &num); xx+=2; $Insect (xx-1, xx,num); -Insect (xx,xx-1, num); -         } thescanf"%d",&num); -Insect (xx+1, t,num);WuyiInsect (t,xx+1, num); the     } - } Wu voidin3 () - { About     intI,j,num; $      for(i=1; i<n;++i) -       for(j=1; j<m;++j) -      { -scanf"%d",&num); AInsect ((I-1) * (M-1)*2+j*2-1, (I-1) * (M-1)*2+j*2, num); +Insect ((I-1) * (M-1)*2+j*2, (I-1) * (M-1)*2+j*2-1, num); the      } - } $ voidInit () the { thescanf"%d%d\n",&n,&m); thes=0; T= (n1) * (M-1)*2+1; the in1 (); - in2 (); in in3 (); the } the voidSPFA () About { the     intnum,mp; thedist[s]=0; the Q.push (s); +      while(!q.empty ()) -     { theNum=q.front (); Q.pop (); vis[num]=0;Bayimp=Point[num]; the          while(mp>0) the         { -             if(dist[v[mp]]>dist[num]+C[MP]) -             { thedist[v[mp]]=dist[num]+C[MP]; the                 if(vis[v[mp]]==0) the                 { thevis[v[mp]]=1; Q.push (V[mp]); -                 } the             } themp=NEXT[MP]; the         }94     } theprintf"%d\n", Dist[t]); the } the intMain ()98 { Aboutmemset (Dist,127,sizeof(Dist)); -memset (Point,0,sizeof(point));101Memset (Next,0,sizeof(next));102memset (Vis,0,sizeof(Vis));103memset (V,0,sizeof(v));104 init (); the SPFA ();106     return 0;107}
View Code

• Floor plan Properties 1. (Euler's formula) if a connected plan has n points, M-and F-faces, then f=m-n+2 2. Each plot g has a planar graph with its dual g*n,g* each point corresponds to a polygon n in G

Bzoj 1001 Wolf Catch rabbit Dual diagram +SPFA

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.