Girls and Boys
Time limit:20000/10000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 8863 Accepted Submission (s): 4077
Problem DescriptionThe Second year of the University somebody started a study on the romantic relations between the Studen Ts. 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.
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, for n subjects.
For each given data set, the program should write to standard output a line containing the result.
Sample Input7 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 21: (1) 0 2: (1) 0
Sample OUTPUT5 2
Sourcesoutheastern Europe 2000
recommendjgshining | We have carefully selected several similar problems for you:1150 1151 1281 1507 15,282 Figure maximum Independent set = number of vertices-maximum number of matches. The subject searches from the entire point set and does not separate the point set, which is equivalent to searching two times. So the maximum number of matches is divided by two.
1#include <cstdio>2#include <cstring>3#include <iostream>4 using namespacestd;5 intmap[1010][1010], dis[1010], vis[1010];6 intN;7 BOOLDfs (inta)8 {9 for(inti =0; I < n; i++)Ten { One if(Map[a][i] &&!Vis[i]) A { -Vis[i] =1; - if(!dis[i] | |Dfs (Dis[i])) the { -Dis[i] =A; - return true; - } + } - } + return false; A } at intMain () - { - intQ, M, GG; - while(~SCANF ("%d", &N)) - { -memset (Map,0,sizeof(map)); inmemset (DIS,0,sizeof(DIS)); - for(inti =0; I < n; i++) to { +scanf"%d: (%d)", &q, &m); - for(inti =1; I <= m; i++) the { *scanf"%d", &GG); $MAP[Q][GG] =1;Panax Notoginseng } - } the intsum =0; + for(inti =0; I < n; i++) A { thememset (Vis,0,sizeof(Vis)); + if(Dfs (i)) -sum++; $ } $printf"%d\n", n-sum/2); - } - return 0; the}
1#include <cstdio>2#include <cstring>3#include <iostream>4 using namespacestd;5 intmap[1010][1010], dis[1010], vis[1010];6 intN;7 BOOLDfs (inta)8 {9 for(inti =0; I < n; i++)Ten { One if(Map[a][i] &&!Vis[i]) A { -Vis[i] =1; - if(!dis[i] | |Dfs (Dis[i])) the { -Dis[i] =A; - return true; - } + } - } + return false; A } at intMain () - { - intQ, M, GG; - while(~SCANF ("%d", &N)) - { -memset (Map,0,sizeof(map)); inmemset (DIS,0,sizeof(DIS)); - for(inti =0; I < n; i++) to { +scanf"%d: (%d)", &q, &m); - for(inti =1; I <= m; i++) the { *scanf"%d", &GG); $MAP[Q][GG] =1;Panax Notoginseng } - } the intsum =0; + for(inti =0; I < n; i++) A { thememset (Vis,0,sizeof(Vis)); + if(Dfs (i)) -sum++; $ } $printf"%d\n", n-sum/2); - } - return 0; the}
Hangzhou Electric 1068--girls and Boys (the largest independent set of two graphs)