hdu 1068 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
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 description of each student, in the following format
student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
or
student_identifier:(0)
For each given data set, the program should write to standard output a line containing the result.
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
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 (最大独立集)的更多相关文章
- HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)
HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...
- HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1068 Girls and Boys(匈牙利算法求最大独立集)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1068 Girls and Boys (二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU——1068 Girls and Boys
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1068 Girls and Boys (二分图最大独立集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 有n个同学,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合 ...
- HDU 1068 Girls and Boys(最大独立集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 题目大意:有n个人,一些人认识另外一些人,选取一个集合,使得集合里的每个人都互相不认识,求该集合 ...
- hdu - 1068 Girls and Boys (二分图最大独立集+拆点)
http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...
- (step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)
题目大意:第一行输入一个整数n,表示有n个节点.在接下来的n行中,每行的输入数据的格式是: 1: (2) 4 6 :表示编号为1的人认识2个人,他们分别是4.6: 求,最多能找到多少个人,他们互不认识 ...
随机推荐
- Cocos2d-x 学习笔记(11.8) DelayTime ReverseTime TargetedAction ActionFloat Blink TintTo TintBy ResizeTo ResizeBy
1. DelayTime 通过create方法create(float d)设置时长,update方法没有任何操作.可以用于动作之间的延迟. 2. ReverseTime create方法create ...
- 5. Sersync实时同步
rsync+Sersync数据的实时同步 sersync介绍 1.什么是实时同步 监控一个目录的变化, 当该目录触发事件(创建\删除\修改) 就执行动作, 这个动作可以是 rsync同步 ,也可以是其 ...
- Kafka源码研究--Comsumer获取partition下标
背景 由于项目上Flink在设置parallel多于1的情况下,job没法正确地获取watermark,所以周末来研究一下一部分,大概已经锁定了原因: 虽然我们的topic只设置了1的partitio ...
- Spring MVC(3)Spring MVC 高级应用
一.Spring MVC 的数据转换和格式化 前面的应用,都只是用HandlerAdapter去执行处理器. 处理器和控制器不是一个概念,处理器是在控制器功能的基础上加上了一层包装,有了这层包装,在H ...
- LogViewer解君之忧
LogViewer是一款查看和搜索大型文本文件的工具,能够很快速的查看记事本无法打开的大容量文件,比如大数据的日志文件或数据库文件等,可支持最大4GB的大容量. 一.下载地址链接(中文破解版): ht ...
- Excel在线预览(通过poi转html,含里面的图片)
支持03和07excel转html,直接上代码 测试类 /** * 主方法 * @author asus * */ public class App2 { public static void mai ...
- SpringBoot是如何加载配置文件的?
前言 本文针对版本2.2.0.RELEASE来分析SpringBoot的配置处理源码,通过查看SpringBoot的源码来弄清楚一些常见的问题比如: SpringBoot从哪里开始加载配置文件? Sp ...
- tomcat的虚拟路径的配置
在一些项目中有时候需要把一些文件(例如图片.视频)存储在硬盘上的,如果是把文件在放在硬盘上的话,怎么才能访问到这些文件昵. 好了.下面就为大家讲讲如何利用tomcat 虚拟路径访问硬盘上的文件.总共有 ...
- Django学习day2——Django安装与环境配置
安装 Django 文章中python版本为3.65 这里以windows7为例,在pip目录下运行pip install Django就能安装django最新版本(本文为django2.2版本) 也 ...
- Docker实战总结
>>> 目录 <<< Docker简介 Docker优势 Docker基本概念 Docker安装使用 Docker常用命令 Docker镜像构建 Docker本地仓 ...