Girls and Boys

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8470    Accepted Submission(s): 3890

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
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
二分图求最大独立集:
最大独立集==节点数-最大匹配数
#include<stdio.h>
#include<string.h>
#define MAX 1100
int vis[MAX],map[MAX][MAX],stu[MAX];
int t;
int find(int x)
{
int i;
for(i=0;i<t;i++)
{
if(map[x][i]&&vis[i]==0)
{
vis[i]=1;
if(stu[i]==0||find(stu[i]))
{
stu[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int n,m,i,j,sum,a,b;
while(scanf("%d",&t)!=EOF)
{
memset(stu,0,sizeof(stu));
memset(map,0,sizeof(map));
for(i=0;i<t;i++)
{
scanf("%d: (%d)",&a,&n);
while(n--)
{
scanf("%d",&b);
map[a][b]=1;
}
}
sum=0;
for(i=0;i<t;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
sum++;
}
printf("%d\n",t-sum/2);
}
return 0;
}

hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】的更多相关文章

  1. POJ 1466 Girls and Boys (匈牙利算法 最大独立集)

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 10912   Accepted: 4887 D ...

  2. HDU - 1068 Girls and Boys(二分匹配---最大独立集)

    题意:给出每个学生的标号及与其有缘分成为情侣的人的标号,求一个最大集合,集合中任意两个人都没有缘分成为情侣. 分析: 1.若两人有缘分,则可以连一条边,本题是求一个最大集合,集合中任意两点都不相连,即 ...

  3. (step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)

    题目大意:第一行输入一个整数n,表示有n个节点.在接下来的n行中,每行的输入数据的格式是: 1: (2) 4 6 :表示编号为1的人认识2个人,他们分别是4.6: 求,最多能找到多少个人,他们互不认识 ...

  4. hdu1068 Girls and Boys 匈牙利算法(邻接表)

    #include <cstdio> #include <algorithm> #include <cstring> #include <vector> ...

  5. hdu 1068 Girls and Boys(匈牙利算法求最大独立集)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. 【HDOJ】1068 Girls and Boys

    匈牙利算法,最开始暴力解不知道为什么就是wa,后来明白,一定要求最优解.查了一下匈牙利算法相关内容,大致了解. #include <stdio.h> #include <string ...

  8. hdu 1068 Girls and Boys (最大独立集)

    Girls and BoysTime Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. poj 1466 Girls and Boys(二分图的最大独立集)

    http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submis ...

随机推荐

  1. z-index使用以及失效的处理方法

    1.一般z-index的使用是在有两个重叠的标签,在一定的情况下控制其中一个在另一个的上方出现. 2.z-index值越大就越是在上层.z-index:9999:z-index元素的position属 ...

  2. sonar-maven-plugin问题

    问题: jenkins本地构建时sonar报错 StackOverflow问题 [ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven ...

  3. emment语法

    emment插件语法.md 元素 div → <div></div>foo → <foo></foo> 嵌套运算符 子: > div>ul& ...

  4. POJ 1129 Channel Allocation 四色定理dfs

    题目: http://poj.org/problem?id=1129 开始没读懂题,看discuss的做法,都是循环枚举的,很麻烦.然后我就决定dfs,调试了半天终于0ms A了. #include ...

  5. uva 10881 - Piotr's Ants

    这个题的突破点就在于蚂蚁不能够穿过对方,故相对位置不变: 另外,又可以把蚂蚁看成运动方向不变: 代码: #include<cstdio> #include<algorithm> ...

  6. 在openshift上自定义node.js的版本

    https://github.com/ramr/nodejs-custom-version-openshift 由于是线上服务器,一步一步来: 先把上面的工程拉下来,覆盖到初始化的工程里,提交,让服务 ...

  7. QLGame 2d Engine 搭建2d游戏原理

    大家好,2d引擎基于opengl(es) 3d技术,是因为这样比之前的ddraw有很多好处! 1.坐标采用浮点数,可以进行曲线移动 2.如果在ddraw的对图片进行缩放和旋转的时候,是基于点像素的操作 ...

  8. 【UVA 1411】 Ants (KM)

    Young naturalist Bill studies ants in school. His ants feed onplant-louses that live on apple trees. ...

  9. 【HDU 5370】 Tree Maker(卡特兰数+dp)

    Tree Maker Problem Description Tree Lover loves trees crazily. One day he invents an interesting gam ...

  10. 【BZOJ 1319】 Sgu261Discrete Rootsv (原根+BSGS+EXGCD)

    1319: Sgu261Discrete Roots Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 389  Solved: 172 Descriptio ...