• 博客访问： 1139116
• 博文数量： 196
• 博客积分： 4141
• 博客等级： 中将
• 技术积分： 2253
• 用 户 组： 普通用户
• 注册时间： 2009-03-21 20:04

2019年（31）

2016年（1）

2014年（16）

2011年（8）

2010年（25）

2009年（115）

2009-06-30 17:58:37

Boys and Girls

 Time Limit:5s Memory limit:32M Accepted Submit:73 Total Submit:276

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.

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`

Output

`52`
 ```#include #include #include int num; int one[15000], two[15000]; int mat[500], tmat[500]; int find(int v) {     int i;     for (i = one[v]; i < one[v + 1]; ++i)     {         if (tmat[two[i]] == -1)         {             tmat[two[i]] = 1;             if (mat[two[i]] == -1 || find(mat[two[i]]))             {                 mat[two[i]] = v;                 mat[v] = two[i];                 return 1;             }         }     }     return 0; } int match() {     int i, j, n;     for (i = 0; i < num; ++i)         mat[i] = -1;     n = 0;     for (i = 0; i < num; ++i)     {         if (mat[i] == -1)         {             for (j = 0; j < num; ++j)                 tmat[j] = -1;             n += find(i);         }     }     return n; } int main() {     int i, j;     int v, n, t, l;     while (scanf("%d", &num) != EOF)     {         l = 0;         for (i = 0; i < num; ++i)         {             scanf("%d: (%d)", &v, &n);             one[v] = l;             for (j = 0; j < n; ++j)             {                 scanf("%d", &t);                 two[l++] = t;             }         }         one[i] = l;         printf("%d\n", num - match());     }     return 0; } ```

0