HDU 1068 - Girls and Boys
求一个集合最多几个人,其之间任意两人没有暧昧关系。
二分图匹配
最大独立集 = 总点数 - 最大匹配数
匈牙利算法
因为每个同学都在二分图的两侧
当 A与B匹配时,B与A也匹配
所以 所求的最大匹配数要除以2
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
const int maxn=;
int n,a,m,b;
vector<int>map[maxn];
int link[maxn];
int vis[maxn];
bool dfs(int t)
{
int size=map[t].size();
for(int i=;i<size;i++)
{
int x=map[t][i];
if(!vis[x])
{
vis[x]=;
if(link[x]==-||dfs(link[x]))
{
link[x]=t;
return ;
}
}
}
return ;
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=;i<n;i++)
{
scanf("%d: (%d)",&a,&m);
map[i].clear();
for(int j=;j<m;j++)
{
scanf("%d",&b);
map[a].push_back(b);
}
}
memset(link,-,sizeof(link));
int ans=;
for(int i=;i<n;i++)
{
memset(vis,,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%d\n",n-ans/);
}
}
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 (最大独立集)
Girls and BoysTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 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 思路: 求一集合满足,两两之间没有恋爱关系 思路: 最大独立点集=顶点数-最大匹配数 这里给出的 ...
- HDU 1068 Girls and Boys(模板——二分图最大匹配)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1068 Problem Description the second year of the univ ...
随机推荐
- PHP学习笔记二十一【全局变量】
<?PHP //定义全局变量 global $a; $a=9; //给全局变量赋值 function test1() { global $a; $a=45; } test1(); echo $a ...
- 类似QQ侧滑菜单功能实现
之前的那文章简单实现了菜单侧拉功能,但是做不到像QQ那样导航条和tabBar一起移动...之后在网上找资料,有了思路,就自个写了个demo试试水. 先创建QHLMainController控制器,并把 ...
- MySql学习之数据库管理
一步一步学习mysql数据,首先是mysql数据的管理操作. 1. 创建数据库 命令格式:create database [if not exists] database_name. 实际的使用过程中 ...
- Java中关于final关键字
final关键字,大学时一直没有理解,伴随到工作,郁闷......也可能大学真的没认真去学习 首先,final给人一看英语单词 不就是最终的嘛,最终的什么的呢 ? 小张现在就带大家 学习下..... ...
- CSS3弹性盒模型布局模块介绍
来源:Robert’s talk原文:http://robertnyman.com/2010/12/02/css3-flexible-box-layout-module-aka-flex-box-in ...
- 如何调用EcStore中的API接口
EcStore系统已内置了丰富的API接口供外部系统调用(接口列表见文章最下面),外部系统具体如何调用这些API呢? 例如有一个PHP的论坛需要调用ecstore系统内一个商品的详情,则可以使用b2c ...
- information_schema.triggers 学习
mysql实例中的每一个trigger 对应到information_schema.triggers 中有一行 1.information_schema.triggers 表的常用列: 1.trigg ...
- 【转】Objective-C 与 Runtime:为什么是这样?
原文地址: http://t.cn/RyyNIXd?u=2483713130&m=3884400301576073&cu=2483713130 笔者非常高兴能为Objective-C写 ...
- freebsd安装和图形界面安装
通过上述的安装以后只有命令行界面,没有图形界面,如果想使用X Window就需要安装X 11和GNOME(或KDE). 1. 安装X 11(用root账户) 在确保虚拟机的CD-ROM加载了FreeB ...
- c# 控制IE浏览器
原文 http://www.cnblogs.com/love2wllw/archive/2010/05/19/1739327.html 想写一个桌面程序,用C#.程序运行后,会用IE打开指定的网页,并 ...