Hdu 3657 least cut active/odd/Even square fetch typical questions/least cut

Source: Internet
Author: User

Hdu 3657 least cut active/odd/Even square fetch typical questions/least cut

Question: Take the number of squares. If the number is adjacent, pay a certain price. (Cost: 2 * (X & Y) (start to use the fee stream, knock the upgrade version 3820, kneel down ...)

Graph creation: for adjacent problems, the classic method is to create a bipartite graph for parity. For the adjacent two-point edge 2 * (X & Y), source-> X edge, Y-> sink edge, the weight w is the vertex weight.

Ans = total Point Weight-minimum cut: if the cut edge is source-> X, it indicates that x is not selected (it is cut edge, and the value must be the smallest in the path ), if the cut edge is a Y-sink point, the same is true. If the cut edge is X-> Y, the Y point is selected and the X point is selected, split to w (2 * (X & Y )).

I do not understand its essence. I don't know why. (I started to knock a few more else and kept kneeling !)

#include
 
  #include
  
   #include
   
    #include
    
     #include
     
      #include
      
       using namespace std;const int inf=0x3f3f3f3f;const int maxv=2550,maxe=20000;int nume=0;int head[maxv];int e[maxe][3];void inline adde(int i,int j,int c){ e[nume][0]=j;e[nume][1]=head[i];head[i]=nume; e[nume++][2]=c; e[nume][0]=i;e[nume][1]=head[j];head[j]=nume; e[nume++][2]=0;}int ss,tt,n,m,k;int vis[maxv];int lev[maxv];bool bfs(){ for(int i=0;i
       
        q; q.push(ss); vis[ss]=1; while(!q.empty()) { int cur=q.front(); q.pop(); for(int i=head[cur];i!=-1;i=e[i][1]) { int v=e[i][0]; if(!vis[v]&&e[i][2]>0) { lev[v]=lev[cur]+1; vis[v]=1; q.push(v); } } } return vis[tt];}int dfs(int u,int minf){ if(u==tt||minf==0)return minf; int sumf=0,f; for(int i=head[u];i!=-1&&minf;i=e[i][1]) { int v=e[i][0]; if(lev[v]==lev[u]+1&&e[i][2]>0) { f=dfs(v,minf
        
         =0) adde(i*m+j,(i-1)*m+j,2*(mapp[i][j]&mapp[i-1][j])); if(i+1
         
          =0) adde(i*m+j,i*m+j-1,2*(mapp[i][j]&mapp[i][j-1])); if(j+1
          
           %d:%d\n",i,e[j][0],e[j][2]); }*/}void init(){ nume=0;sums=0; ss=n*m+2;tt=ss+1; for(int i=0;i<=tt;i++) { head[i]=-1; must[i]=0; }}int main(){ while(scanf("%d%d%d",&n,&m,&k)!=EOF) { init(); read_build(); int ans; ans=sums-dinic(); printf("%d\n",ans); } return 0;}
          
         
        
       
      
     
    
   
  
 


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.