hdu1068Girls and Boys(二分匹配,最大独立集)
2014-07-28 11:15
274 查看
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.
Sample Input
Sample Output
[/code]
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.
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给出他们之间认识关系,求最大两两不认识。[code]#include<stdio.h> #include<vector> #include<string.h> #include<iostream> using namespace std; vector<int>map[1005]; int vist[1005],match[1005]; int find(int u) { for(int j=0;j<map[u].size();j++){ int v=map[u][j]; if(!vist[v]){ vist[v]=1; if(match[v]==-1||find(match[v])) { match[v]=u; return 1; } } } return 0; } int main() { int n,a,b,m,ans; while(scanf("%d",&n)>0) { for(int i=0;i<=n;i++) map[i].clear(),match[i]=-1; for(int i=0;i<n;i++) { scanf("%d: (%d)",&a,&m); while(m--) { scanf("%d",&b); map[a].push_back(b); } } ans=0; for(int i=0;i<n;i++) { memset(vist,0,sizeof(vist)); if(find(i)) ans++; } printf("%d\n",n-ans/2); } }
[/code]
相关文章推荐
- Light OJ 1373 Strongly Connected Chemicals 二分匹配最大独立集
- 【POJ2771】【最大二分匹配】【反向图最小独立集】
- hdu 4169 二分匹配最大独立集 ***
- Light OJ 1373 Strongly Connected Chemicals 二分匹配最大独立集
- hdu 3829 Cat VS Dog (二分匹配 求 最大独立集)
- poj 3692 Kindergarten(二分匹配,最大独立集)
- HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)
- HDU 1068 Girls and Boys【二分匹配之最大独立集】
- HDU 3829 Cat VS Dog (二分匹配求最大独立集)
- POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题
- hrbust 1469 Wrong Answer【最大独立集---二分匹配】
- hdu3829 二分匹配 最大独立集
- hdu3829 二分匹配 最大独立集
- hdu 1068 Girls and Boys(最大独立集,二分匹配)
- 二分匹配最大独立集——hdu1068
- Girls and Boys【二分匹配之最大独立集】
- poj2771 Guardian of Decency 二分匹配之最大独立集
- POJ 2771 Guardian of Decency(二分匹配,最大独立集)
- HDU 2768 Cat vs. Dog 【二分匹配之最大独立集】
- HDU5556Land of Farms 【二分匹配+最大独立集+奇偶分类】