Bzoj 1001: [BeiJing2006] Wolf Scratch rabbit floor plan min cut

Source: Internet
Author: User

The maximum flow of a plan run can be converted to its dual graph to run the shortest circuit of a ring corresponding to a cut find the smallest ring (i.e. the shortest path) is very much sought, attention to the establishment of auxiliary edge

Add read-in optimization but the time or the general estimate is Dij write bad big God do not spray ~ ~ ~

/************************************************************** problem:1001 user:96655 language:c++ Resu lt:accepted time:1724 Ms Memory:95120 kb****************************************************************/#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<iostream>#include<cstdlib>#include<queue>#include<map>#include<Set>#include<vector>#include<cmath>#include<stack>#include<utility>using namespacestd;Const intmaxn=1001000;Const intinf=0x3f3f3f3f;structedge{intV,w,next;} EDGE[MAXN*6];inthead[maxn*2],p,n,m,y;voidAddedge (intUintVintW) {EDGE[P].W=W; EDGE[P].V=v; Edge[p].next=Head[u]; Head[u]=p++;}structasd{intx,d; ASD (intAintb): X (a), d (b) {}BOOL operator< (ConstASD &e)Const    {        returnD>E.D; }};p Riority_queue<asd>Q;intdis[maxn*2],vis[maxn*2];voidDijkstra (ints) {memset (Vis,0,sizeof(VIS));  while(!q.empty ()) Q.pop ();  for(intI=0; i<=y; i++) Dis[i]=INF; Dis[s]=0; Q.push (ASD (s),0));  while(!Q.empty ()) {ASD e=Q.top ();        Q.pop (); if(Vis[e.x])Continue; Vis[e.x]=1;  for(intI=head[e.x]; i!=-1; I=Edge[i].next) {            intv=edge[i].v; if(dis[v]>dis[e.x]+EDGE[I].W) {Dis[v]=dis[e.x]+EDGE[I].W;            Q.push (ASD (V,DIS[V)); }        }    }}voidReadint&x) {    CharC;  while((C=getchar ()) <'0'|| C>'9'); X=c-'0';  while((C=getchar ()) >='0'&& c<='9') x= (x<<3) + (x<<1) +c-'0';}intMain () {read (n);    Read (m); if(n==1|| m==1)    {        if(n>m) swap (N,M); intans=Inf,a;  for(intI=1; i<m; i++) {scanf ("%d",&a); Ans=min (A,ans); }        if(Ans==inf) printf ("0\n"); Elseprintf"%d\n", ans); return 0; } memset (Head,-1,sizeof(head)); P=0; Y= (n1) * (M-1)*2+1; intw,u,v;  for(intI=1; i<=n; i++)    {         for(intj=1; j<m; J + +) {Read (w); if(i==1) {u= ((I-1) * (M-1) +j) *2;                Addedge (U,Y,W);            Addedge (Y,U,W); }            Else if(i==n) {u= ((I-2) * (M-1) +j) *2-1; Addedge (0, u,w); }            Else{u= ((I-1) * (M-1) +j) *2; V= ((I-2) * (M-1) +j) *2-1;                Addedge (U,V,W);             Addedge (V,U,W); }        }    }     for(intI=1; i<n; i++)    {         for(intj=1; j<=m; J + +) {Read (w); if(j==1) {u= ((I-1) * (M-1) +j) *2-1; Addedge (0, u,w); Addedge (U,0, W); }            Else if(j==m) {u= ((I-1) * (M-1) +j-1)*2;                Addedge (U,Y,W);             Addedge (Y,U,W); }            Else{u= ((I-1) * (M-1) +j) *2-1; V= ((I-1) * (M-1) +j-1)*2;                Addedge (U,V,W);             Addedge (V,U,W); }        }    }     for(intI=1; i<n; i++)    {         for(intj=1; j<m; J + +) {Read (w); U= ((I-1) * (M-1) +j) *2-1; V= ((I-1) * (M-1) +j) *2;            Addedge (U,V,W);        Addedge (V,U,W); }} Dijkstra (0); printf ("%d\n", Dis[y]); return 0;}
View Code

Bzoj 1001: [BeiJing2006] Wolf Scratch rabbit floor plan 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.