http://acm.hdu.edu.cn/showproblem.php?pid=2444
Problem Descriptionthere is a group of students. Some of them may know, and while others don ' t. For example, A and b know each other, B and C know each other. It is not imply, A and C know each other.
Now is given all pairs of students who know each of the other. Your task is to divide, the students into, groups so, any, and students in the same group don ' t know each other. If This goal can is achieved, then arrange them into double rooms. Remember, only Paris appearing in the previous given set can live in the same, which means only known students can Li ve in the same.
Calculate the maximum number of pairs that can is arranged into these double rooms.
Inputfor each data set:
The first line gives integers, N and M (1<n<=200), indicating there is n students and m pairs of students who kn Ow each of the other. The next m lines give such pairs.
Proceed to the end of file.
Outputif These students cannot is divided into and groups, print "No". Otherwise, print the maximum number of pairs that can is arranged in those rooms.
Sample Input
4 41 21 31 42 36 51 21 31 42 53 6
Sample Output
No3
Source2008 Asia Harbin Regional Contest Online
/**hdu2444 binary map matching, first determine whether it is two points to the main idea: given a graph, determine whether it is a two-figure if the maximum number of matching numbers to solve the problem-solving ideas: For is not a two-point diagram: All points can be divided into a couple of points, each part of the point is not connected, we can use DFS search to know For the matching of the binary graph, use the Hungarian algorithm */#include <string.h> #include <stdio.h> #include <algorithm> #include <vector > #include <iostream>using namespace std;const int Maxn=202;vector <int>vec[maxn];int Linker[maxn];bool Used[maxn];int n,m;int matchs[maxn],cnt[maxn];bool dfs (int u) {for (int i=0;i<vec[u].size (); i++) {int V=ve C[u][i]; if (!used[v]) {used[v]=true; if (linker[v]==-1| | DFS (Linker[v])) {linker[v]=u; return true; }}} return false;} int Hungary () {int res=0; int u; memset (LINKER,-1,SIZEOF (linker)); for (int u=1;u<=n;u++) {memset (used,false,sizeof (used)); if (DFS (U)) res++; } return res; BOOL Judge (int x,int y) {int i; for (int i=0;i<vec[x].size (); i++) {if (cnt[vec[x][i]]==0) {cnt[vec[x][i]]=y^1; Matchs[vec[x][i]]=true; if (!judge (vec[x][i],y^1)) return false; } else if (cnt[vec[x][i]]==y) return false; } return true; BOOL Matched ()///whether the figure is two (memset) (matchs,false,sizeof (matchs)); for (int i=1;i<=n;i++) {if (Vec[i].size () &&!matchs[i]) {memset (cnt,0,sizeof (CNT)); Cnt[i]=1; Matchs[i]=true; if (!judge (i,1)) return false; }} return true; int main () {while (~scanf ("%d%d", &n,&m)) {for (int i=1;i<=n;i++) {if (vec[i].size ()) vec[i].clear (); } while (m--) {int u,v; scanf ("%d%d", &u,&v); Vec[u].push_back (v); Vec[v].push_back (U); } if (matched ()) printf ("%d\n", Hungary ()/2); else printf ("no\n"); } return 0;}
hdu2444 the matching of the binary graph, first determine whether it is a two-point graph