*HDU 1068 二分图
Girls and Boys
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10929 Accepted Submission(s): 5100
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.
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
2
// 模板 匈牙利算法dfs 最大独立集=总结点数-最大匹配(有向图);最大独立集=总结点数-最大匹配/2(无向图),(图中任意两个顶点都不相连的顶点集合。)
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int mp[][],vis[],link[];
int Mu,Mv,n; //左集合点数,右集合点数,总点数
int dfs(int x) //找增广路。
{
for(int i=;i<Mv;i++)
{
if(!vis[i]&&mp[x][i])
{
vis[i]=;
if(link[i]==-||dfs(link[i]))
{
link[i]=x;
return ;
}
}
}
return ;
}
int Maxcon()
{
int ans=;
memset(link,-,sizeof(link));
for(int i=;i<Mu;i++)
{
memset(vis,,sizeof(vis));
if(dfs(i)) ans++;
}
return ans;
}
int main()
{
int a,b,c;
while(scanf("%d",&n)!=EOF)
{
memset(mp,,sizeof(mp));
for(int i=;i<n;i++)
{
scanf("%d: (%d)",&a,&c);
while(c--)
{
scanf("%d",&b);
mp[a][b]=mp[b][a]=;
}
}
Mu=Mv=n;
printf("%d\n",n-Maxcon()/);
}
return ;
}
*HDU 1068 二分图的更多相关文章
- Girls and Boys HDU - 1068 二分图匹配(匈牙利)+最大独立集证明
最大独立集证明参考:https://blog.csdn.net/qq_34564984/article/details/52778763 最大独立集证明: 上图,我们用两个红色的点覆盖了所有边.我们证 ...
- HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)
HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...
- hdu 5727 二分图+环排列
Necklace Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- 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 本题求二分图最大独立点集.因为最大独立点集=顶点数-最大匹配数.所以转化为求最大匹配.因为没有给 ...
- HDU 1068 Girls and Boys(模板——二分图最大匹配)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1068 Problem Description the second year of the univ ...
- hdu 1068 Girls and Boys 二分图的最大匹配
题目链接:pid=1068">http://acm.hdu.edu.cn/showproblem.php? pid=1068 #include <iostream> #in ...
- 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: 求,最多能找到多少个人,他们互不认识 ...
随机推荐
- Coursera-Getting and Cleaning Data-Week2-课程笔记
Coursera-Getting and Cleaning Data-Week2 Saturday, January 17, 2015 课程概述 week2主要是介绍从各个来源读取数据.包括MySql ...
- [Linux & Mysql] Linux下Mysql的基本操作
1. 连接Mysql 1.1 连接到本机上的Mysql 键入命令mysql -u root -p,回车后提示你输密码.注意用户名前可以有空格也可以没有空格,但是密码前必须没有空格,否则让你重新输入密码 ...
- Rails的三种环境----开发环境,生产环境和测试环境
Rails 的三个环境 Rails 的应用程序预设提供了三种不同的执行模式: development environment 开发模式,用在你的开发的时候 test environment 测试模式, ...
- html嵌入样式表
1.针对文件中的字体还有属性进行设置主要设置文字的大小及其颜色问题,未涉及div飘操作 处理页面CSS 先检测该内容部分是否已经设定了样式,如果没有单独设定再按照总体设计进行限定. eg: h1 h ...
- parse_str怎么用php
1.需求 了解parse_str的用法 2.作用 parse_str接受2个参数,把第一个参数查询字符串解析到第二个参数数组当中,会覆盖数组中原来的值 parse_str($_SERVER['QUER ...
- Python之模块,迭代器与生成器
本节涉及内容: 1. 迭代器和生成器 2. 递归 3. 字符串格式化 4. 模块 内置模块 自定义模块 第三方模块 5. 序列化的模块 json pickle (一). 迭代器和生成器: 迭代器: ...
- ABAP BAPI 销售订单生产交货单函数
TYPES: BEGIN OF ty_so, vbeln LIKE vbap-vbeln, posnr LIKE vbap-posnr, END ...
- Sublime 3 如何设置xftp 保存自动上传
采用sublime SFTP插件,直接保存CentOS服务器的NodeJS文件,这样调试起来很方便,当然得配上 一直采用File -> SFTP/FTP -> Setup Se ...
- maven install 构建报错(2)
错误:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin: 2.3 . 2 :compile ( default ...
- .NET LINQ标准查询运算符
标准查询运算符概述 “标准查询运算符”是组成语言集成查询 (LINQ) 模式的方法. 大多数这些方法都在序列上运行,其中的序列是一个对象,其类型实现了 IEnumerable<T> ...