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