Bzoj 2132: Enclosure plan

Source: Internet
Author: User

1#include <cstdio>2#include <iostream>3#include <cstring>4 #defineM 1000095 #defineINF 21390621436 using namespacestd;7 intn,m,a[102][102],b[102][102],c[102][102],tot,cnt=1, t,ans,head[m],d[m],q[2*m],next[Ten*m],u[Ten*m],v[Ten*M];8 intxx[4]={0,0,1,-1},yy[4]={1,-1,0,0};9 BOOLBFS ()Ten { Onememset (D,0,sizeof(int) * (t+1)); A     intH=0, t=1; -q[1]=0; -d[0]=1; the      for(;h<t;) -       { -h++; -         intp=Q[h]; +          for(intI=head[p];i;i=Next[i]) -           if(!d[u[i]]&&V[i]) +             { Ad[u[i]]=d[p]+1; at                 if(D[t]) -                   return 1; -t++; -q[t]=U[i]; -             } -       } in     return 0; - } to intDinic (intSintf) + { -     if(s==T) the       returnF; *     intrest=F; $      for(intI=head[s];i&&rest;i=Next[i])Panax Notoginseng       if(v[i]&&d[u[i]]==d[s]+1) -         { the             intnow=dinic (U[i],min (rest,v[i)); +             if(!Now ) Ad[u[i]]=0; thev[i]-=Now ; +v[i^1]+=Now ; -rest-=Now ; $         } $     returnF-rest;  - } - voidJia1 (intA1,intA2,intA3) the { -cnt++;Wuyinext[cnt]=HEAD[A1]; thehead[a1]=CNT; -u[cnt]=A2; Wuv[cnt]=A3; -     return; About } $ voidJiaintA1,intA2,intA3) - { - jia1 (A1,A2,A3); -Jia1 (A2,A1,0); Atot+=A3; +     return; the } - intMain () $ { thescanf"%d%d",&n,&m); thet=n*m+1; the      for(intI=1; i<=n;i++) the        for(intj=1; j<=m;j++) -scanf"%d",&a[i][j]); in      for(intI=1; i<=n;i++) the        for(intj=1; j<=m;j++) thescanf"%d",&B[i][j]);  About      for(intI=1; i<=n;i++) the        for(intj=1; j<=m;j++) thescanf"%d",&c[i][j]); the      for(intI=1; i<=n;i++) +        for(intj=1; j<=m;j++) -         { the             if((I+J) &1)Bayi swap (a[i][j],b[i][j]); theJia0, (I-1) *m+j,a[i][j]); theJia ((i-1) *m+j,t,b[i][j]); -              for(intk=0;k<4; k++) -               { the                 intnx=i+xx[k],ny=j+Yy[k]; the                 if(!nx| |! ny| | nx>n| | Ny>m) the                   Continue; theJia ((i-1) *m+j, (nx-1) *m+ny,c[i][j]+C[nx][ny]); -tot-=C[i][j]; the               } the         } the      for(; BFS ();)94Ans+=dinic (0, INF); theprintf"%d\n", tot-ans); the     return 0; the}

The graph black and white dyeing s to I (black dots) with the edge capacity for agriculture, S to J (White point) with the edge capacity of the work, I to the t edge capacity for the work, J-T edge capacity for agriculture, I and J edge capacity for mixed income.

Bzoj 2132: Enclosure plan

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.