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. freeswitch GUI界面(portal)

    1.控制台 加载模块 load mod_xml_rpc 2.ip:8080/portal 进行登录  账号 : freeswitch  密码 : works 让模块随着freeswitch启动进行加载 ...

  2. 从CSDN搬过来

    https://blog.csdn.net/qq_34416123 从CSDN搬过来 神奇的代码竟然没有弄成博客园这里面的格式 所以以前的很多博客的代码都是直接放在那里了. 懒得去改了.

  3. MySQL主从复制与读写分离(非原创,谢绝膜拜)

    MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践 Mysql作为目前世界上使用最广泛的免费数据库,相信所有从事系统运维的工程师都一定接触过.但在实际的生产环境中, ...

  4. jquery weui ajax滚动加载更多

    手机端使用jquery weui制作ajax滚动加载更多. 演示地址:http://wx.cnkfk.com/nuol/static/fpage.html 代码: <!DOCTYPE html& ...

  5. ASP.NET-model验证

    在ASP.NET的model中,可以定义下面的这种属性,来实现前台签证字符串 RegularExpression(@"(|.*(?=.{6,})(?=.*\d)(?=.*[a-zA-Z]). ...

  6. angular-基础

    AngularJs特点: 1.依赖注入 2.模块化 3.双向绑定 4.语义化标签 当网页加载完毕,AngularJS 自动开启. ng-app 指令告诉 AngularJS,<div> 元 ...

  7. SPOJ 4491

    不妨先把所有要求的素数的对的个数写出来 f(2)=u(1)G(2)+u(2)*G(2*2)+u(3)*G(2*3)+.....u(k2)*G(2*k2) f(3)=u(1)G(3)+u(2)*G(2* ...

  8. MongoDB数据查询详解

    查询全部 ​ db.infos.find(); db.infos.find({"url":"www.baidu.com"}); id不要显示出来 db.info ...

  9. Vmware Workstation及Centos6.8 的安装

    转自:http://www.mamicode.com/info-detail-1462939.html 一.什么是Vmware Workstation Vmware Workstation是Vmwar ...

  10. HD-ACM算法专攻系列(6)——Big Number

    题目描述: 源码: #include"iostream" #include"cmath" using namespace std; #define PI 3.1 ...