有一个集合男和一个集合女,给出两集合间一些一一相应关系。问该两集合中的最大独立集的点数。

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

此题中。若(a,b)有关。则(b,a)有关。每个关系算了两次,相当于二分图的两边集合没有分男女。两边都是总人数。

所以此题中答案应该是 顶点总数-最大匹配数/2

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
const int maxn=510;
using namespace std;int mx[maxn],my[maxn],vis[maxn],e[maxn][maxn],n;int path(int i)
{int j;for(j=0;j<n;j++){if(e[i][j]&&!vis[j]){vis[j]=1;if(my[j]==-1||path(my[j])){my[j]=i;mx[i]=j;return 1;}}}return 0;
}int hungry()
{int res=0;memset(mx,-1,sizeof mx);memset(my,-1,sizeof my);for(int i=0;i<n;i++){if(mx[i]==-1){memset(vis,0,sizeof vis);res+=path(i);}}return res;
}int main()
{int a,b,m,i;while(~scanf("%d",&n)){memset(e,0,sizeof e);for(i=0;i<n;i++){scanf("%d: (%d)",&a,&m);while(m--){scanf("%d",&b);e[a][b]=1;}}printf("%d\n",n-hungry()/2);}return 0;
}

hdu1068 Girls and Boys --- 最大独立集相关推荐

  1. poj 1466 Girls and Boys (最大独立集)

    http://poj.org/problem?id=1466 题意:一些 boys 和girls  有暧昧关系,我们要选出 一些人,这些人 任意两个人之间没有暧昧 关系,求最多可以选出 多少人. 题解 ...

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

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

  3. HDU-1068 Girls and Boys

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 the second year of the university somebody start ...

  4. (step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)

    题目大意:第一行输入一个整数n,表示有n个节点.在接下来的n行中,每行的输入数据的格式是: 1: (2) 4 6 :表示编号为1的人认识2个人,他们分别是4.6: 求,最多能找到多少个人,他们互不认识 ...

  5. Girls and Boys||HDU1068

    link:http://acm.hdu.edu.cn/showproblem.php?pid=1068 Problem Description the second year of the unive ...

  6. TZOJ 1321 Girls and Boys(匈牙利最大独立集)

    描述 the second year of the university somebody started a study on the romantic relations between the ...

  7. Girls and Boys

    http://acm.hdu.edu.cn/showproblem.php?pid=1068 题意:在大学校园里男女学生存在某种关系,现在给出学生人数n,并给出每个学生与哪些学生存在关系(存在关系的学 ...

  8. zoj 1137 || 1466 Girls and Boys

    二分图的最大独立集=顶点数-二分图的最大匹配数 二分图的最小顶点覆盖=二分图的最大匹配数 二分图的最小路径覆盖=顶点数-二分图的最大匹配数 zoj上居然没写数据范围...poj写了. 这题是求最大独立 ...

  9. 【HDOJ】1068 Girls and Boys

    匈牙利算法,最开始暴力解不知道为什么就是wa,后来明白,一定要求最优解.查了一下匈牙利算法相关内容,大致了解. 1 #include <stdio.h> 2 #include <st ...

最新文章

  1. PyTorch常用代码段整理合集,建议收藏!
  2. 测试start backup和ndb_restore
  3. 【Groovy】Groovy 扩展方法 ( 实例扩展方法配置 | 扩展方法示例 | 编译实例扩展类 | 打包实例扩展类字节码到 jar 包中 | 测试使用 Thread 实例扩展方法 )
  4. 安装redis提示[test] error 2_安装PHP Redis扩展
  5. Android中scrollview与webview冲突事件
  6. 多个服务器数据互通_5月23日部分服务器数据互通公告!
  7. 如何使div的浏览器窗口高度为100%
  8. 比特币锚定币总锁仓量触及38亿美元 创历史新高
  9. mac java jni_Mac OS上编译JNI的动态库
  10. 08.存储Cinder→5.场景学习→12.Ceph Volume Provider→5.Detach Volume
  11. 针对英特尔xtu超频软件安装失败以及英伟达GeForce Experience安装程序无法继续的解决方法
  12. Homography单应性矩阵原理
  13. 动态范围控制算法基本原理
  14. 为什么最近iOS开发岗位那么多(第一篇)
  15. 陀螺仪的进动及其数学描述
  16. Html之 图像标记
  17. 教你给大量视频快速调整色调的方法
  18. opencv中批量读取图片并保存
  19. root创建用户以及Xshell连接命令
  20. android xml 平铺,Android 图片平铺实现方式

热门文章

  1. Some Essential JavaScript Questions And Answers(2)
  2. Qt学习三 - 菜单栏、工具栏、状态栏
  3. 针对ie9写特殊的样式
  4. android开源项目框架大全:《IT蓝豹》
  5. linux系统——fread()与read()函数族区别
  6. PB9.0实现下拉数据列表的实现
  7. PostgreSQL 行变列的小应用
  8. Mathematics for Computer Graphics
  9. 《.NET应用架构设计:原则、模式与实践》新书博客--试读-1.1.2 架构师的职责
  10. xxx must either be declared abstract or implement abstract method ‘call(T1, T2)‘ in ‘Function2