http://acm.hdu.edu.cn/showproblem.php?pid=1068

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

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
 
Source
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:  1150 1151 1281 1507 1528 
 
 
(男女没有关系)最大独立子集=总点数-最大匹配数
因为男女人数不是分开的,所以在同一集合,最大匹配数/=2;
 #include <cstring>
#include <cstdio> using namespace std; const int N();
int n,match[N];
bool map[N][N],vis[N]; bool find(int u)
{
for(int v=;v<n;v++)
if(map[u][v]&&!vis[v])
{
vis[v]=;
if(!match[v]||find(match[v]))
{
match[v]=u;
return true;
}
}
return false;
} inline void read(int &x)
{
x=; register char ch=getchar();
for(;ch>''||ch<'';) ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-'';
} int AC()
{
for(int ans=;~scanf("%d",&n);ans=)
{
for(int v,u,q,i=;i<n;i++)
{
read(u);
for(read(q);q--;)
read(v),map[u][v]=;
}
for(int i=;i<n;i++)
{
if(find(i)) ans++;
memset(vis,,sizeof(vis));
}
printf("%d\n",n-ans/);
memset(map,,sizeof(map));
memset(match,,sizeof(match));
}
return ;
} int I_want_AC=AC();
int main(){;}

HDU——T 1068 Girls and Boys的更多相关文章

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

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

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

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

  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

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

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

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

  6. hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】

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

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 有n个同学,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合 ...

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

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

  9. [HDU] 1068 Girls and Boys(二分图最大匹配)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1068 本题求二分图最大独立点集.因为最大独立点集=顶点数-最大匹配数.所以转化为求最大匹配.因为没有给 ...

随机推荐

  1. HDU 2048 神、上帝以及老天爷( 错排 )

    链接:传送门 思路:错排模板,典型错排问题,n个人所有人都不会抽到自己的方案数为 Dn = (n-1) * (Dn-1 + Dn-2) /******************************* ...

  2. python学习笔记:第三天

    day03: 1.python中所有的变量都可以改变 2.Print(name)   打印 3.Del name  删除 4.python中python2与python3不能兼容,需要分别安装pyth ...

  3. div,span等标签支持focus/blur事件

    <div tabindex="0" hidefocus="true" onfocus='alert("得到焦点");' onblur= ...

  4. [terry笔记]python三级菜单

    把三级菜单输出,选择后逐层显示,”b“返回上一级菜单. menu = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, 'google':{} }, '中关村': ...

  5. 【转】 C#获取当前程序运行路径的方法集合

    [转] C#获取当前程序运行路径的方法集合 //获取当前进程的完整路径,包含文件名(进程名). string str = this.GetType().Assembly.Location; resul ...

  6. Ubuntu 安装 Courier New字体和雅黑consolas字体

    一直觉得Ubuntu下的字体不是很好,但毕竟不影响使用,然后作开发的时候eclipse的字体完全没有windows下的两大适合编成的字体courier new 和consloas .可以使用系统安装字 ...

  7. ubuntu下使用Nexus搭建Maven私服

    ubuntu下使用Nexus搭建Maven私服 1.私服简介: 私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件.有了私服之后,当 Maven 需要下载构件时,直接请求私服, ...

  8. [Tools] Create your own mobile emulator device by using Chrome dev tool

    Using the New Device Emulation Interface The Device Emulation interface changed a bit with the newer ...

  9. 【原创】Zend Framework 2框架之MVC

    ZendFramework 2框架之MVC 作者:sys(360电商技术组) 1.前言 Zend Framework 2是zend官方推出的php开源框架,基于php5.3.他全然採用面向对象的代码实 ...

  10. hdu 4882 ZCC Loves Codefires(贪心)

    # include<stdio.h> # include <algorithm> # include <string.h> using namespace std; ...