Girls and Boys |
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
Total Submission(s): 249 Accepted Submission(s): 163 |
Problem Description the second year of the university somebody started a study on the romantic relations between the students. The relation “romantically involved” is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been “romantically involved”. The result of the program is the number of students in such a set. The input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description: the number of students the description of each student, in the following format student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ... or student_identifier:(0) The student_identifier is an integer number between 0 and n-1, for n subjects. For each given data set, the program should write to standard output a line containing the result. |
Output |
Sample Input 70: (3) 4 5 61: (2) 4 62: (0)3: (0)4: (2) 0 15: (1) 06: (2) 0 130: (2) 1 21: (1) 02: (1) 0 |
Sample Output 52 |
Source Southeastern Europe 2000 |
Recommend JGShining |
/*初次思考:给出你一个点阵,然后让你求最大连通图的点数并查集想法,找点#错误:题意没理解明白题意:找出一个最大集合使得任意两个人没有关系因为有关系的肯定是男女(暂时不考虑性取向的问题)所以就将整个关系图,联系到了二分图上,进而用到二分匹配问题的解决方案用到“匈牙利算法”要求最大的没有关系的集合,就是总顶点数-最大匹配数*/#includeusing namespace std;int n,u,m,v;/***********************二分匹配模板**************************/const int MAXN=1010;int g[MAXN][MAXN];//编号是0~n-1的 int linker[MAXN];//记录匹配点i的匹配点是谁bool used[MAXN];bool dfs(int u)//回溯看能不能通过分手来进行匹配{ int v; for(v=0;v