题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068

思路:

求一集合满足,两两之间没有恋爱关系

思路:

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

这里给出的关系,看似有向边,实则是无向边,那么按照二分匹配处理的话,相当于一个人看作两个人来用,最后还是顶点数目-最大二分匹配数

因为之间一个人当作两个人用,二分匹配数目减半,即 = n - match()/2

或者也可以写成 = ( 2n -  match() )/2 更容易理解

题目中n的大小没有说明,最好开大一点,最后测得的大小在500以内

代码:

 #include <stdio.h>
#include <string.h>
const int maxn=;
int n;
int g[maxn][maxn],vis[maxn],who[maxn];
bool F(int x) {
for(int i=; i<n; ++i) {
if(g[x][i]&&!vis[i]) {
vis[i]=;
if(who[i]==-||F(who[i])) {
who[i]=x;
return true;
}
}
}
return false;
}
int main() {
while(~scanf("%d",&n)) {
memset(g,,sizeof(g));
memset(who,-,sizeof(who));
int temp=n,u,v,num;
while(temp--) {
scanf("%d: (%d)",&u,&num);
while(num--) {
scanf("%d",&v);
g[u][v]=g[v][u]=;
}
}
int sum=;
for(int i=; i<n; ++i) {
memset(vis,,sizeof(vis));
if(F(i)) sum++;
}
printf("%d\n",n-sum/);
}
return ;
}

hdu 1068 Girls and Boys 最大独立点集 二分匹配的更多相关文章

  1. [HDU] 1068 Girls and Boys(二分图最大匹配)

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

  2. POJ Girls and Boys (最大独立点集)

                                                                Girls and Boys Time Limit: 5000MS   Memo ...

  3. HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)

    HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...

  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 Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDU——1068 Girls and Boys

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

  8. hdu 1068 Girls and Boys (最大独立集)

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

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

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

随机推荐

  1. web项目生成war包的问题

    今天面试一家公司,问我生成war包的命令是什么? 当时没明白,就说自己用的eclipse直接右键 export --->war 完了重启tomcat(第一种) 好久没用maven了.回来一查才明 ...

  2. LeetCode 205. Isomorphic Strings (同构字符串)

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  3. LeetCode 561. Array Partition I (数组分隔之一)

    Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1 ...

  4. LeetCode 495. Teemo Attacking (提莫攻击)

    In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...

  5. js解析器的执行原理

    首先看一段代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> < ...

  6. 译:Asp.Net Identity与Owin,到底谁是谁?

    送给正在学习Asp.Net Identity的你 :-) 原文出自 trailmax 的博客AspNet Identity and Owin. Who is who. Recently I have ...

  7. zabbix 2.2.20 安装详解(Centos6.9)

    环境说明 [root@centos ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@centos ~]# uname -a L ...

  8. HTML学习笔记 基础表格案例 第二节 (原创) 参考使用表

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. ueditor插入百度音乐无法播放-403 问题

    简单记录一下,其实403是因为百度音乐设置了禁止外部连接引用,因此 几乎所有的百度音乐播放都会提示403. 注意:预览页面(dialog/music/music.html)和实际插入页面(uedito ...

  10. centos6.7系统安装流程

    虚拟机创建centos的过程,如下: 1.首先创建一个空白文件 2.打开虚拟机,打开文件,或者页面的<创建虚拟机>,如下: 3.打开之后如下所示,选择自定义,Linux崇尚自由 4.第四步 ...