Girls and Boys
Time Limit: 5000MS |
|
Memory Limit: 10000K |
Total Submissions: 11134 |
|
Accepted: 4981 |
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
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
Test instructions
In the second year of college, people began to study the "romantic" relationship between male and female students, the so-called "romantic" relationship between male and female students, give you each student's number and their romantic relationship, please find a largest student collection, so that the collection of any two students no romantic relationship between The number of students seeking this collection.
Analytical:
Naked the largest independent set of problems, first build a two-point diagram, or the most primitive demolition of the map, each point to split into about two points, there are relations between the points to build the edge, and then the maximum number of matches, but here to note, because the relationship is mutual, so here to find the maximum number of matches is twice times, to/2
The maximum independent set of the binary graph = Two The number of points in the graph-two the maximum matching numbers of the graphs.
#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 550using namespace Std;int map[ Maxn][maxn];int used[maxn];int link[maxn];int n;void init () {memset (map, 0, sizeof (map));} void Getmap () {for (int j = 0; J < N; ++j) {int id, m, A; scanf ("%d: (%d)", &id, &m); for (int i = 0; i < m; ++i) {scanf ("%d", &a); Map[id][a] = 1; }}}bool dfs (int x) {for (int i = 0; i < n; ++i) {if (Map[x][i] &&!used[i]) {Used[i] = 1 ; if (link[i] = = 1 | | DFS (LINK[I])) {link[i] = x; return true; }}} return false;} int Hungary () {int ans = 0; memset (link, 1, sizeof); for (int i = 0; i < n; ++i) {memset (used, 0, sizeof (used)); if (Dfs (i)) ans++; } return ans; int main () {while (scanf ("%d", &n)! = EOF) {init (); Getmap (); int sum = Hungary (); printf ("%d\n", sum); printf ("%d\n", N-SUM/2); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 1466 && ZOJ 1137--girls and Boys "dichotomy && maximum point independent set"