Girls and Boys

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7044    Accepted Submission(s): 3178

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
 

题意:在大学校园里男女学生存在某种关系。如今给出学生人数n,并给出每一个学生与哪些学生存在关系(存在关系的学生一定是异性)。如今让你求一个学生集合,这个集合中随意两个学生之间不存在这种关系。

输出这种关系集合中最大的一个的学生人数。

(网上翻译)

最大独立集问题 :在N个点的图G中选出m个点。使这m个点两两之间没有边.求m的最大值. 假设图G满足二分图条件。则能够用二分图匹配来做.最大独立集点数 = N - 最大匹配数
#include"stdio.h"
#include"string.h"
#define N 505
int g[N][N];
int mark[N];
int link[N];
int n;
int find(int k) //寻找和能和K节点匹配的右节点
{
int i;
for(i=0;i<n;i++) //遍历数组
{
if(g[i][k]&&!mark[i]) //边存在,且是第一次訪问
{
mark[i]=1;
if(link[i]==-1||find(link[i]))
{ //该点未匹配或者和该点匹配的左节点能够另外匹配
link[i]=k;
return 1;
}
}
}
return 0; //匹配失败
}
int main()
{
int i,j,u,v,m;
while(scanf("%d",&n)!=-1)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
g[i][j]=0;
for(i=0;i<n;i++)
{
scanf("%d: (%d)",&u,&m);
while(m--)
{
scanf("%d",&v);
g[u][v]=1;
}
}
memset(link,-1,sizeof(link)); //记录每一个二分图的右半边节点匹配的左节点标号
int ans=0;
for(i=0;i<n;i++)
{
memset(mark,0,sizeof(mark)); //标记数组。防止反复訪问一个节点
if(find(i))
ans++;
}
printf("%d\n",n-ans/2); //最大独立集点数 = N - 最大匹配数
}
return 0;
}

hdu 1068 Girls and Boys(匈牙利算法求最大独立集)的更多相关文章

  1. HDU 1068 Girls and Boys(模板——二分图最大匹配)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1068 Problem Description the second year of the univ ...

  2. HDU 1068 - Girls and Boys

    求一个集合最多几个人,其之间任意两人没有暧昧关系. 二分图匹配 最大独立集 = 总点数 - 最大匹配数 匈牙利算法 因为每个同学都在二分图的两侧 当 A与B匹配时,B与A也匹配 所以 所求的最大匹配数 ...

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

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

  4. HDU 1068 Girls and Boys(最大独立集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 题目大意:有n个人,一些人认识另外一些人,选取一个集合,使得集合里的每个人都互相不认识,求该集合 ...

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

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

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

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

  7. HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)

    HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...

  8. hdu 1068 Girls and Boys (二分匹配)

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

  9. HDU——1068 Girls and Boys

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

随机推荐

  1. dropdb - 删除一个现有 PostgreSQL 数据库

    SYNOPSIS dropdb [ option...] dbname DESCRIPTION 描述 dropdb 删除一个现有 PostgreSQL 数据库. 执行这条命令的人必须是数据库超级用户, ...

  2. 20针,14针,10针JTAG引脚对应关系

    J-Link是常用的调试工具,用于程序的调试和下载.常用的J-Link的的接口有很多种,常见的有20针,14针和10针. J-Link可以使用JTAG方式下载调试程序,也可以使用SWD方式.从引脚方面 ...

  3. (转)关于treap的板子理解

    关于treap的板子理解: 关于结构体的定义:(一般平衡树无法理解的变量名):v:节点的值:size:子节点的个数(包括自己):cnt:相同的值的副本数:l:左儿子:r:右儿子: 右旋:父亲变成左儿子 ...

  4. net core 使用ef生成实体类(SqlServer)

    1)打开程序包管理器控制台 2)输入命令  Install-Package Microsoft.EntityFrameworkCore.SqlServer 3)输入命令  Install-Packag ...

  5. 字典(trie)树--从入门到入土

    今天再来认识一个强大的数据结构. 字典树又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词 ...

  6. noip2019——动态规划刷题历程

    加粗的是值得总结的 从洛谷的普及题开始刷题: 背包式dp(有些技巧的) 1.p2639[USACO09OCT]Bessie的体重问题 -p1049取模意义下01背包 技巧:重量=价值 2.金明的预算问 ...

  7. 关于C/C++的一些思考(5)

    运算符重载函数的限制: 五个不能实现重载的符号:".", ".*", "::", "?", "sizeof&q ...

  8. (13) openssl ca(签署和自建CA)

    用于签署证书请求.生成吊销列表CRL以及维护已颁发证书列表和这些证书状态的数据库.因为一般人无需管理crl,所以本文只介绍openssl ca关于证书管理方面的功能. 证书请求文件使用CA的私钥签署之 ...

  9. python中的函数的分类

    函数的种类 传参的基本要求 默认参数 *args 关键字参数 **kwargs 普通函数 带参数 默认参数 def text(a,b=2) print("haha") print( ...

  10. mysql启动问题

    /usr/local/mysql/bin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13 - Permission denied) - ...