求一个集合最多几个人,其之间任意两人没有暧昧关系。

二分图匹配

最大独立集 = 总点数 - 最大匹配数

匈牙利算法

因为每个同学都在二分图的两侧

当 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的更多相关文章

  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 (最大独立集)

    Girls and BoysTime Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  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(二分图最大匹配)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1068 本题求二分图最大独立点集.因为最大独立点集=顶点数-最大匹配数.所以转化为求最大匹配.因为没有给 ...

  9. hdu 1068 Girls and Boys 最大独立点集 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 思路: 求一集合满足,两两之间没有恋爱关系 思路: 最大独立点集=顶点数-最大匹配数 这里给出的 ...

  10. HDU 1068 Girls and Boys(模板——二分图最大匹配)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1068 Problem Description the second year of the univ ...

随机推荐

  1. hadoop下载

    1.输入网址: http://mirrors.cnnic.cn/apache/hadoop/common/ 2.选择需要的版本进行点击下载

  2. JSP脚本元素上机手册

    L3 <JSP基础>上机手册 内容回顾 脚本元素<%! %> <%= %> <% %> 注释元素 JSP指令元素 JSP动作元素 上机目标 掌握脚本元素 ...

  3. (转) Pointers

    原地址 http://www.cplusplus.com/doc/tutorial/pointers/ Pointers In earlier chapters, variables have bee ...

  4. poj1200Crazy Search (哈希)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Crazy Search Time Limit: 1000MS   Memory ...

  5. [转]PictureEx.h和PictureEx.cpp源文件

    要显示一个gif,网上找了个,子类化了MFCl图片控件,用着方便,记一下 转自:http://www.bccn.net/Article/net/vcnet/jszl/200709/6386.html ...

  6. html标签元素分类

    元素分类 html中的标签元素大体分为三种不同的类型:块状元素.内联元素(又叫行内元素)和内联块状元素. 常用的块状元素有: <div>.<p>.<h1>...&l ...

  7. ie下没有背景色bug的解决方法

    鼠标经过下面的二级菜单的时候,在ie下面,收缩上去了,给这个二级菜单加了背景后,就是正常的,这个是ie下面的一个bug,解决方法:background-img:url(123.jpg):url里面的图 ...

  8. Spring HibernateTemplate的使用

    Spring HibernateTemplate的使用 2008-03-25 11:38 2020人阅读 评论(0) 收藏 举报 springbeanhibernatesessiondaoclass ...

  9. MySQL--query-cache

    知识准备: 1.mysql 的query-cache是什么?  mysql可以把执行完成的select 语句和这个select 语句对应的结果集缓存起来:下次再用调用相同的select 语句时就直接返 ...

  10. sql中插入多条记录-微软批处理

    这是使用批处理的一个例子: System.IO.StreamWriter messagelog = null; string messageString = ""; SqlConn ...