Girls and Boys
Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13556    Accepted Submission(s): 6385
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

C/C++:

 #include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define INF 0xffffff
using namespace std;
const int my_max = ; int n, m, a, b, my_G[my_max][my_max], my_book[my_max], my_right[my_max]; bool my_dfs(int x)
{
for (int i = ; i < n; ++ i)
{
if (my_G[x][i] && !my_book[i])
{
my_book[i] = ;
if (!my_right[i] || my_dfs(my_right[i]))
{
my_right[i] = x;
return true;
}
}
}
return false;
} int my_hungarian()
{
int my_cnt = ;
for (int i = ; i < n; ++ i)
{
memset (my_book, , sizeof(my_book));
if (my_dfs(i))
++ my_cnt;
}
return my_cnt / ;
} int main()
{
while (~scanf("%d", &n))
{
memset(my_right, , sizeof(my_right));
memset(my_G, , sizeof(my_G));
for (int i = ; i < n; ++ i)
{
scanf("%d: (%d)", &a, &m);
while (m --)
{
scanf("%d", &b);
my_G[a][b] = ;
}
} printf("%d\n", n - my_hungarian());
}
return ;
}

hdu 1068 Girls and Boys (最大独立集)的更多相关文章

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

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

  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 Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

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

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

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

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

  8. hdu - 1068 Girls and Boys (二分图最大独立集+拆点)

    http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...

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

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

随机推荐

  1. 一文了解Mysql

    文章原创于公众号:程序猿周先森.本平台不定时更新,喜欢我的文章,欢迎关注我的微信公众号. Redis系列到上一篇已经全部结束了,从本篇开始进入Mysql系列文章专题.本篇作为Mysql系列专题的开篇文 ...

  2. Redis 到底是怎么实现“附近的人”这个功能的?

    前言:针对“附近的人”这一位置服务领域的应用场景,常见的可使用PG.MySQL和MongoDB等多种DB的空间索引进行实现.而Redis另辟蹊径,结合其有序队列zset以及geohash编码,实现了空 ...

  3. Java Web 学习(1) —— Servlet

    Java Web 学习(1) —— Servlet 一. 什么是 Servlet Java Servlet 技术是Java体系中用于开发 Web 应用的底层技术. Servlet 是运行在 Servl ...

  4. 游图邦YOTUBANG是如何搭建生态系统的?

    现在的我们最关心的一个问题就是任何一个行业,如果没有办法很好的落地,就算描绘的非常美好,那也只是空中楼阁.昙花一现而已,它无法实现长久的一个发展.互联网时代呢,就是一个流量为王的一个时代,谁拥有庞大的 ...

  5. python中基本运算符

    基本运算符 a // b 取整 a % b 取余 a ** b a 的b次方 a == b 判断运算符左右两边值是否相等 a != b 判断运算符左右两边值是否不等 a > b a >= ...

  6. (JavaScript) base64 字符串 和 ArrayBuffer 之间转换

    base64 --> ArrayBuffer function base64ToUint8Array(base64String) { const padding = '='.repeat((4 ...

  7. python:将网页图片保存到本地

    1.requests库介绍 在python中,有一个非常好用的网络请求库requests,使用它可以发起网络请求,并获取网页返回的内容.同时,也可以进行网页图片下载 requests是使用Apache ...

  8. 前端技术之:通过plop生成Controller的方法与步骤

    # Controller的生成 开发者可以通过plop命令生成各种类型的控制器类(Normal.Restful.View), 以下是示例生成步骤. 1. 执行以下命令: plop controller ...

  9. QHDYZ模拟赛20191027 提前透题

    你们想的美 我给你们透一下题目名称 别刷博客了快去做题

  10. 【XSY2505】tree

    Description 机房断网了!xj轻而易举地撬开了中心机房的锁,拉着zwl走了进去.他们发现中心主机爆炸了. 中心主机爆炸后分裂成了 n 块碎片,但碎片仍然互相连接,形成一个树的结构.每个碎片有 ...