Floor Plan Maximum Flow

Source: Internet
Author: User

To build a dual graph, the shortest path is the maximum flow

The surface of the connection s,t is the new S, the periphery is the new T,

Directed graph connecting edge direction depending on the situation

#include <cstdio>#include<cstring>#include<queue>#defineLL Long Long#defineINF 1000000000using namespacestd; LL dis[500000]; intb[500000]; intnext[5000000],des[5000000],cnt=0, nd[500000],n; LL len[5000000]; structdata{intnum;       LL dis; BOOL operator< (ConstData &a)Const {          return(a.dis<dis);  }  }; Priority_queue<data>Heap; voidAddedge (intUintVintl) {next[++cnt]=nd[u];nd[u]=CNT; DES[CNT]=v;len[cnt]=l; }    voidbuild () {intT; memset (ND,-1,sizeof(ND));  for(intI=1; i<=n+1; i++)         for(intj=1; j<=n;j++) {scanf ("%d",&t); if(i==1) Addedge ((I-1) *n+j,n*n+1, t);Else               if(i==n+1) Addedge (0, (I-2) *n+j,t);ElseAddedge ((i-1) *n+j, (I-2) *n+j,t); }             for(intI=1; i<=n;i++)      for(intj=0; j<=n;j++) {scanf ("%d",&t); if(j==0) Addedge (0, (I-1) *n+j+1, t);Else         if(j==n) Addedge (i*n,n*n+1, t);ElseAddedge ((i-1) *n+j, (I-1) *n+j+1, T); }          for(intI=1; i<=n+1; i++)       for(intj=1; j<=n;j++) {scanf ("%d",&t); if(i==1) Addedge (n*n+1, (I-1) *n+j,t);Else          if(i==n+1) Addedge ((n1) *n+j,0, t);ElseAddedge ((i-2) *n+j, (I-1) *n+j,t); }                for(intI=1; i<=n;i++)       for(intj=0; j<=n;j++) {scanf ("%d",&t); if(j==0) Addedge ((I-1) *n+j+1,0, t);Else          if(j==n) Addedge (n*n+1, (I-1) *n+j,t);ElseAddedge ((i-1) *n+j+1, (I-1) *n+j,t); }    }    voidDij () {inttcnt;  for(intI=0; i<=n*n+1; i++) {Data t;t.num=i;t.dis=Dis[i];heap.push (t);}  while(!Heap.empty ()) {Data T=Heap.top ();        Heap.pop (); if(B[t.num])Continue;  for(intP=nd[t.num];p!=-1;p =Next[p])if(dis[des[p]]>dis[t.num]+Len[p]) {tcnt++; DIS[DES[P]]=dis[t.num]+Len[p]; Data Tmp;tmp.num=des[p];tmp.dis=Dis[des[p]];        Heap.push (TMP); } B[t.num]=1; }  }  intMain () {scanf ("%d",&N);      Build (); A for(intI=1;i<500000; i++) dis[i]=1000000000; memset (b,0,sizeof(b)); dis[0]=0;            Dij (); printf ("%lld", dis[n*n+1]); }//bzoj2007

Floor Plan Maximum Flow

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.