[HDU] 1068 Girls and Boys(二分图最大匹配)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1068
本题求二分图最大独立点集。因为最大独立点集=顶点数-最大匹配数。所以转化为求最大匹配。因为没有给出男女,所以每个人都用了两遍,所以结果应该除以2。
#include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdbool.h>
#include<time.h>
#include<stdlib.h>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define LL long long
#define INF 0x3f3f3f3f
#define A first
#define B second
#define PI 3.14159265358979323
const int N=+;
int n,m,f[N],g[N][N],link[N]; void init()
{
clr(f,);
clr(g,);
clr(link,-);
} bool find(int x)
{
for(int i=;i<n;i++) {
if(!f[i] && g[x][i]) {
f[i]=;
if(link[i]==- || find(link[i])) {
link[i]=x;
return true;
}
}
} return false;
} int hungary()
{
int ans=;
for(int i=;i<n;i++) {
clr(f,);
if(find(i)) ans++;
}
return ans;
} int main()
{
int u,v; while(~scanf("%d",&n)) {
init();
for(int i=;i<n;i++) {
scanf("%d: (%d)",&u,&m);
while(m--){
scanf("%d",&v);
g[u][v]=;
}
}
printf("%d\n",n-hungary()/);
} return ;
}
[HDU] 1068 Girls and Boys(二分图最大匹配)的更多相关文章
- 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 二分图的最大匹配
题目链接: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 有n个同学,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合 ...
- 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: 求,最多能找到多少个人,他们互不认识 ...
- HDU 1068 Girls And Boys 二分图题解
版权声明:本文作者靖心.靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...
- 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) ...
随机推荐
- python word操作深入
python 把word转html:上传页面<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...
- 虚拟机LUN扩大后,重新分区
[root@ywcrmdb ~]# fdisk -l Disk /dev/sda: 751.6 GB, 751619276800 bytes 255 heads, 63 sectors/track, ...
- LINQPad 调试
var ss=from o in Orders from od in OrderDetails.Where(od=>od.OrderId == od.OrderId) from c in Cou ...
- vim 中按键映射问题
按键映射关键字的组成开始让我摸不着头脑,查了资料,然后来做一个log 按键绑定命令:模式前缀(缺省为normal) + 递归前缀(缺省为空) + map 前缀表示生效范围,递归前缀表示是否递归查找命令 ...
- Linux开关机命令详解
Linux系统的开关机主要涉及(shutdown,reboot,poweroff,halt,init)这几条命令,本文对其使用详解如下: 一.命令简介 shutdown,poweroff,reboot ...
- powerdesigner 字段大小写转换\id 自增
转换:tools --> model options-->naming convention name code 自增: 在你所要设为自增型的键上(比如你的id)双击 ,弹出一个Colu ...
- selenium page object model
Page Object Model (POM) & Page Factory in Selenium: Ultimate Guide 来源:http://www.guru99.com/page ...
- js中的call()与apply()
js中的call()函数和apply()函数: 1.主要作用:是用于指定作用域和传参 (1)用于指定作用域 window.color = "red"; var o = { colo ...
- Android中的windowSoftInputMode属性详解
这篇文章主要介绍了Android中的windowSoftInputMode属性详解,本文对windowSoftInputMode的9个属性做了详细总结,需要的朋友可以参考下 在前面的一篇文章中 ...
- MySQL数据库的环境及简单操作
***********************************************声明*************************************************** ...