POJ-3692 Kindergarten binary Graph maximum matching

Source: Internet
Author: User

The main topic: Give N Boys, M girls, and K to men and women to understand the relationship, the same sex people know each other. Now asks you to pick out the K-man, so that this K-man 22 knows each other.

Problem-solving ideas: To pick the people you know, you can rule out the people you don't know.
Can be divided into two points set, a point set is a male, a point set is a female, two points set of the line represents two people do not know each other, so as long as we find the largest non-mutual understanding of the matching number, and then use N + M-non-mutual recognition of the matching number, get people are all people know each other

#include <cstdio>#include <cstring>#include <vector>using namespace STD;Const intN = About;intN, M, K;intVis[n], Link[n], g[n][n]; vector<int>R[n];voidInit () { for(inti =1; I <= N; i++) r[i].clear ();memset(g,0,sizeof(g));intx, y; for(inti =0; I < K; i++) {scanf("%d%d", &x, &y); G[x][y] =1; } for(inti =1; I <= N; i++) for(intj =1; J <= M; J + +)if(!g[i][j]) R[i].push_back (j);memset(Link,0,sizeof(link));}BOOLDfsintu) { for(inti =0; I < r[u].size (); i++) {if(Vis[r[u][i]])Continue; Vis[r[u][i]] =1;if(!link[r[u][i] | | DFS (LINK[R[U][I])) {Link[r[u][i]] = u;return true; }    }return false;}voidHungary () {intAns =0; for(inti =1; I <= N; i++) {memset(Vis,0,sizeof(VIS));if(Dfs (i)) ans++; }printf("%d\n", n + m-ans);}intMain () {intCAS =1; while(scanf("%d%d%d", &n, &m, &k)! = EOF && n + M + k) {printf("Case%d:", cas++);        Init ();    Hungary (); }return 0;}

POJ-3692 Kindergarten binary Graph maximum matching

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.