HDU 1068 Girls and Boys(最大独立集合)
来源:互联网 发布:c语言郝斌教学视频 编辑:程序博客网 时间:2024/06/04 17:52
Girls and Boys
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7555 Accepted Submission(s): 3459
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.
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
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给出0-n-1的人认识的人,求多少个人互不认识。也就是求最大独立集合!二分图最大独立集合 = 节点数 - 最大匹配数#include <cstdio>#include <string.h>#include <stdlib.h>#include <stdio.h>#include <algorithm>using namespace std;int xx[501],yy[501];int map[501][501];int v[501];int n;int dfs(int r){ for(int i=0;i<n;i++) { if(map[r][i]&&!v[i]) { v[i]=1; if(yy[i]==-1 || dfs(yy[i])) { xx[r]=i; yy[i]=r; return 1; } } } return 0;}int erfen(){ int ans=0; memset(xx,-1,sizeof(xx)); memset(yy,-1,sizeof(yy)); for(int i=0;i<n;i++) { if(xx[i]==-1) { memset(v,0,sizeof(v)); ans+=dfs(i); } } return ans;}int main(){ while(~scanf("%d",&n)) { //scanf("%d%d",&nx,&ny); memset(map,0,sizeof(map)); for(int i=1;i<=n;i++) { int a,b; scanf("%d: (%d)",&a,&b); for(int j=0;j<b;j++) { int t; scanf("%d",&t); map[a][t]=1; } } int ans=erfen(); printf("%d\n",n-ans/2); } return 0;}
0 0
- HDU 1068 Girls and Boys(最大独立集合)
- HDU 1068 Girls and Boys(最大独立集)
- hdu 1068 Girls and Boys (最大独立集)
- hdu 1068 Girls and Boys(最大独立集)
- HDU 1068 boys and girls(最大独立集)
- HDU:1068 Girls and Boys(最大独立集)
- hdu 1068 Girls and Boys(最大独立集模板)
- HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)
- hdu 1068 Girls and Boys 最大独立集(最大匹配)
- hdu 1068 Girls and Boys(最大独立集,二分匹配)
- HDU 1068 Girls and Boys 二分最大独立集
- HDU 1068 Girls and Boys 最大独立集
- hdu 1068 Girls and Boys 【最大独立集】
- HDU 1068 — Girls and Boys 最大独立集
- HDU 1068 Girls and Boys【最大独立集】
- poj 1466 && hdu 1068Girls and Boys(最大独立集)
- HDU 1068 Girls and Boys (二分最大独立集)
- HDU 1068 Girls and Boys 最大独立集
- SRM 627 D2L3: BubbleSortWithReversals, dp, 冒泡排序
- NYOJ 2 括号配对问题
- HDU 3038 How Many Answers Are Wrong 并查集 + 权值
- 周测题 河南理工的ACMer要开始组队了 (数学,递推)
- Linux学习笔记(三)Linux文件操作
- HDU 1068 Girls and Boys(最大独立集合)
- can not be used when making a shared object; recompile with -fPIC
- HTML利用第三方框架HTML Parser解析
- hdu 1024 Max Sum Plus Plus
- IOS-时间戳转化时间
- hdu1995汉诺塔V
- mysql使用
- java与c/c++不同的地方
- HDOJ题目2544 最短路(最短路径问题,Dijkstra模板)