hdu1068Girls and Boys
来源:互联网 发布:禁止修改ip软件 编辑:程序博客网 时间:2024/05/17 06:38
Girls and Boys
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9027 Accepted Submission(s): 4159
Total Submission(s): 9027 Accepted Submission(s): 4159
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
Source
Southeastern Europe 2000
题目中由于没有说明男女,所以建图时会有1-2,也会有2-1,
所以求出来的匹配数要2,接下来便是一个最大独立子集问题
题目中由于没有说明男女,所以建图时会有1-2,也会有2-1,
所以求出来的匹配数要2,接下来便是一个最大独立子集问题
#include<bits/stdc++.h>const int MAXN=1010;const int MAXM=2010;struct Edge{ int to,next;}edge[MAXM];int tot;bool used[MAXN];int linker[MAXN];int head[MAXN];void init(){ tot=0; memset(head,-1,sizeof(head));}void addedge(int u,int v){ edge[tot].to=v; edge[tot].next=head[u]; head[u]=tot++;}bool dfs(int u){ for(int i=head[u];i!=-1;i=edge[i].next){ int v=edge[i].to; if(!used[v]){ used[v]=true; if(linker[v]==-1||dfs(linker[v])){ linker[v]=u; return true; } } } return false;}int hungary(int n){ memset(linker,-1,sizeof(linker)); int ret=0; for(int u=0;u<n;u++){ memset(used,false,sizeof(used)); if(dfs(u)) ret++; } //for(int i=0;i<n;i++) //printf("%d %d\n",i,linker[i]); return ret;}int main(){ int k,n,m; int u,v; while(scanf("%d%",&n)!=EOF){ init(); for(int i=0;i<n;i++){ scanf("%d: (%d)",&u,&k); while(k--){ scanf("%d",&v); addedge(u,v); } } printf("%d\n",n-hungary(n)/2); } return 0;}
0 0
- hdu1068Girls and Boys
- HDU1068Girls and Boys(最大独立数)
- HDU1068Girls and Boys二分图最大匹配
- hdu1068Girls and Boys(二分匹配,最大独立集)
- hdu1068Girls and Boys(求二分图的最大独立集)
- Girls and Boys
- hdu1068 Girls and Boys
- Girls and Boys
- zoj1137:Girls and Boys
- poj1466 - Girls and Boys
- hdu1608 Girls and Boys
- A. Boys and Girls
- HDU1068--Girls and Boys
- HDU1068:Girls and Boys
- HDU1068-Girls and Boys
- poj1466--Girls and Boys
- POJ1466 Girls and Boys
- Girls and Boys
- canvas(2)绘制路径,文本,坐标变换
- cocos2d lua 引用protobuf进行通信
- 多线程学习资料
- 调试断点:C160_BREAK_POINT
- 关于使用python Process 参数消除歧义
- hdu1068Girls and Boys
- SQL2008 MSSQLSERVER服务无法启动,报错"17051"怎么解决
- 实现Android左右菜单互拉(动画)
- Spring MVC 4.1.3 + MyBatis 零基础搭建Web开发框架(注解模式哦)
- angular post数据的前端处理方法
- 在最美的时间遇到你
- ksh 函数
- session.flush()与session.clear()的区别及使用环境
- ubuntu 10.04右上角网络管理图标消失解决办法