Description
In the second, 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 was necessary to find out the the maximum set satisfying the condition:there was no and the students in T He set who has been "romantically involved". The result of the program was the number of students in such a set.
Input
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 a integer number between 0 and n-1 (n <=500), for n subjects.
Output
For each given data set, the program should write to standard output a line containing the result.
Sample Input
7
0: (3) 4 5 6
1: (2) 4 6
2: (0)
3: (0)
4: (2) 0 1
5: (1) 0
6: (2) 0 1
3
0: (2) 1 2
1: (1) 0
2: (1) 0
Sample Output
5
2
To the effect that there may be romance between the two opposite sex in the school, it is time to find a group of people who have no romance between them and seek the maximum value of this number. Obviously the problem of the maximum independent set, but because do not know the gender of each person, so the two point set of the binary graph is everyone n, so that the maximum match is the true maximum match twice times, the answer is N-Max match/2
#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <vector>#include <iostream>#include <set>#include <cstring>#include <string>#define MAXN 510#define INF 0xFFFFFFFFusing namespace STD;int Map[MAXN] [MAXN],VIS[MAXN],PRE[MAXN];intNintFindintcur) { for(intI=0; i<n; ++i) {if(!vis[i]&&Map[cur] [i]) {vis[i] =true;if(Pre[i] = =0|| Find (Pre[i])) {pre[i] = cur;return 1; } } }return 0;}intMain () {intM,x,y; while(~scanf("%d", &n)) {GetChar ();memset(Map,0,sizeof(Map));memset(Pre,0,sizeof(pre)); for(intI=0; i<n; ++i) {scanf("%d: (%d)", &x,&m); while(m--) {scanf("%d", &y);Map[x] [y]=1; } }intans=0; for(intI=0; i<=n; ++i) {memset(Vis,0,sizeof(VIS));if(Find (i)) ans++; }printf("%d\n", n-ans/2); }return 0;}
Poj1466--girls and Boys (maximum set of independent points)