HDU 2063 (Hungarian algorithm) roller coaster

Source: Internet
Author: User
Tags define local

There are m girls and N boys. If boys and girls have a crush on each other, they will be connected and asked how many pairs can be matched.

This blog post is well written and does not contain daunting graph theory terms.

Http://blog.csdn.net/dark_scope/article/details/8880547

The core idea is the word "Teng". It doesn't matter if you don't have a sister. Let the old ones change their favorite sister to see if they can "Teng" their favorite sister.

 

 1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 using namespace std; 6  7 const int maxn = 505; 8 int line[maxn][maxn], used[maxn], girl[maxn]; 9 int k, m, n;10 11 bool find(int x)12 {13     for(int j = 1; j <= m; ++j)14     {15         if(line[x][j] && !used[j])16         {17             used[j] = 1;18             if(girl[j] == 0 || find(girl[j]))19             {20                 girl[j] = x;21                 return true;22             }23         }24     }25     return false;26 }27 28 int main(void)29 {30     #ifdef LOCAL31         freopen("2063in.txt", "r", stdin);32     #endif33 34     while(scanf("%d", &k) == 1 && k)35     {36         scanf("%d%d", &n, &m);37         memset(line, 0, sizeof(line));38         memset(girl, 0, sizeof(girl));39         for(int i = 0; i < k; ++i)40         {41             int a, b;42             scanf("%d%d", &a, &b);43             line[a][b] = 1;44         }45         int match = 0;46         for(int i = 1; i <= n; ++i)47         {48             memset(used, 0, sizeof(used));49             if(find(i))    ++match;50         }51         printf("%d\n", match);52     }53     return 0;54 }
Code Jun

 

HDU 2063 (Hungarian algorithm) roller coaster

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.