Poj 2195 Going Home bipartite graph minimum weight matching KM Algorithm

Source: Internet
Author: User

Poj 2195 Going Home bipartite graph minimum weight matching KM Algorithm

Question:

There are n people who want to return to n houses. Each house only allows one person. Ask for the minimum distance and distance for n people.

Analysis:

The minimum weight matching of the bare bipartite graph is done by KM.

Code:

//poj 2195//sep9#include 
 
  using namespace std;const int maxN=128;char g[maxN][maxN];int mx[maxN],my[maxN],hx[maxN],hy[maxN];int w[maxN][maxN];int lx[maxN],ly[maxN],linky[maxN];int visx[maxN],visy[maxN];int slack[maxN];int nx,ny;bool find(int x){visx[x]=true;for(int y=0;y
  
   t)slack[y]=t;}return false;}int KM(){int i,j;memset(linky,-1,sizeof(linky));memset(ly,0,sizeof(ly));for(i=0;i
   
    lx[i])lx[i]=w[i][j];for(int x=0;x
    
     -1)result+=w[linky[i]][i];return result;}int main(){int i,j,n,m;while(scanf("%d%d",&n,&m)==2){if(n==0&&m==0)break;for(i=0;i
     
      

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.