"Algorithm Series learning" Hungarian algorithm

Source: Internet
Author: User

Http://www.cnblogs.com/pony1993/archive/2012/07/25/2607738.html

1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 Const intn=1001;7 intn1,n2,k;8 //N1,n2 is a set of vertices with a two-point graph, where x∈n1,y∈n29 intMap[n][n],vis[n],link[n];Ten //Link records the number of X points that match the point y in the N2 in N1 One  A intFindintx) - { -     inti; the      for(i=1; i<=n2;i++) -     { -         if(Map[x][i]&&!vis[i])//X->i has edges, and node i is not searched -         { +vis[i]=1;//tag node has been searched -             //If I do not belong to the previous match m or I match to the node can find the augmented path +             if(link[i]==0||find (Link[i])) A             { atLink[i]=x;//Update -                 return 1;//Match Success -             } -         }         -     } -     return 0; in } - intMain () to { +     inti,x,y,s=0; -scanf"%d%d%d",&n1,&n2,&k); the      for(i=0; i<k;i++) *     { $scanf"%d%d",&x,&y);Panax Notoginsengmap[x][y]=1; -     } the      for(i=1; i<=n1;i++) +     { Amemset (Vis,0,sizeof(Vis)); the         if(Find (i)) +s++; -     } $printf"%d\n", s); $     return 0; -}
View Code

"Algorithm Series learning" Hungarian algorithm

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.