POJ 1466 Girls and Boys (匈牙利算法 最大独立集)
| Time Limit: 5000MS | Memory Limit: 10000K | |
| Total Submissions: 10912 | Accepted: 4887 |
Description
reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been "romantically involved". The result of the program is the number of students in such a set.
Input
the number of students
the description of each student, in the following format
student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
or
student_identifier:(0)
The student_identifier is an integer number between 0 and n-1 (n <=500 ), for n subjects.
Output
Sample Input
7
0: (3) 4 5 6
1: (2) 4 6
2: (0)
3: (0)
4: (2) 0 1
5: (1) 0
6: (2) 0 1
3
0: (2) 1 2
1: (1) 0
2: (1) 0
Sample Output
5
2
Source
field=source&key=Southeastern+Europe+2000">Southeastern Europe 2000
题目链接:http://poj.org/problem?id=1466
题目大意:一些男的和一些女的有的之间有关系,同性之间无关系,求一个最大的集合。使得里面随意两人没有关系
题目分析:裸的最大独立集问题,建立二分图,然后依据最大独立集=点数-最大匹配,求解就可以,注意因为二分图是双向建立的。求出的最大匹配要除2
#include <cstdio>
#include <cstring>
int const MAX = 505;
bool g[MAX][MAX];
bool vis[MAX];
int cx[MAX], cy[MAX];
int n; int DFS(int x)
{
for(int y = 0; y < n; y++)
{
if(!vis[y] && g[x][y])
{
vis[y] = true;
if(cy[y] == -1 || DFS(cy[y]))
{
cy[y] = x;
cx[x] = y;
return 1;
}
}
}
return 0;
} int MaxMatch()
{
memset(cx, -1, sizeof(cx));
memset(cy, -1, sizeof(cy));
int res = 0;
for(int i = 0; i < n; i++)
{
if(cx[i] == -1)
{
memset(vis, false, sizeof(vis));
res += DFS(i);
}
}
return res;
} int main()
{
while(scanf("%d", &n) != EOF)
{
memset(g, false, sizeof(g));
for(int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
int num;
scanf(": (%d)", &num);
for(int j = 0; j < num; j++)
{
int y;
scanf("%d", &y);
g[x][y] = true;
}
}
int ans = MaxMatch();
printf("%d\n", n - ans / 2);
}
}
POJ 1466 Girls and Boys (匈牙利算法 最大独立集)的更多相关文章
- poj 1466 Girls and Boys(二分图的最大独立集)
http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submis ...
- POJ - 1466 Girls and Boys 二分图+最大独立集
标题效果:有着n学生,有一些同学之间的特殊关系.. .为了一探究竟m学生.要求m免两者之间的学生有没有这样的特殊关系 解决问题的思路:二分图的问题,殊关系是对称的.所以能够将两个点集都设置为n个点.求 ...
- poj 1466 Girls and Boys (最大独立集)
链接:poj 1466 题意:有n个学生,每一个学生都和一些人有关系,如今要你找出最大的人数.使得这些人之间没关系 思路:求最大独立集,最大独立集=点数-最大匹配数 分析:建图时应该是一边是男生的点, ...
- 网络流(最大独立点集):POJ 1466 Girls and Boys
Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...
- poj 1466 Girls and Boys 二分图的最大匹配
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- POJ 1466 Girls and Boys (ZOJ 1137 )最大独立点集
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=137 http://poj.org/problem?id=1466 题目大意: ...
- POJ 1466 Girls and Boys
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题
有n个人, 其中有男生和女生,接着有n行,分别给出了每一个人暗恋的对象(不止暗恋一个) 现在要从这n个人中找出一个最大集合,满足这个集合中的任意2个人,都没有暗恋这种关系. 输出集合的元素个数. 刚开 ...
- poj 1466 Girls and Boys(二分匹配之最大独立集)
Description In the second year of the university somebody started a study on the romantic relations ...
随机推荐
- bzoj3931: [CQOI2015]网络吞吐量(spfa+网络流)
3931: [CQOI2015]网络吞吐量 题目:传送门 题解: 现在有点难受....跳了一个多钟...菜啊... 题意都把做法一起给了....最短路+网路流啊. 不想说话...记得开long lon ...
- EL表达式获取参数值${param.name}等
转自:http://www.html580.com/study/83.html EL表达式获取参数值${param.name}等 (1).${pageContext} 获取到 pageContext ...
- springMVC怎么接收日期类型的参数?
springMVC怎么接收日期类型的参数? springMVC的controller中用实体接受页面传递的参数,并且实体中的属性类型为日期类型,怎么接收呢?如果接收不到会进不到controller中. ...
- HD-ACM算法专攻系列(3)——Least Common Multiple
题目描述: 源码: /**/ #include"iostream" using namespace std; int MinComMultiple(int n, int m) { ...
- SQL 循环30日
循环30日的统计 大概格式是 with Date as ( select cast(DATEADD(mm, DATEDIFF(mm,,getdate()), ) as datetime) Date u ...
- Android框架-Volley(二)
1. ImageRequest的用法 前面我们已经学习过了StringRequest和JsonRequest的用法,并且总结出了它们的用法都是非常类似的,基本就是进行以下三步操作即可: 1. 创建一个 ...
- ListView有Header时的position情况
问题: headerView 为第0个view,item 的 pos会从1开始. 解决方式: position减去 listView.getHeaderViewsCount().例如我想得到list ...
- <Three.js>(第二节)添加长方体
一.实验内容 上一节已经搭好了实验的框架.这一节我们将在屏幕上显示一些几何图形.如下图所示,我们将在屏幕上显示一个正方体. 二.实验步骤 1.创建场景 正像上一节所说,首先我们需要建一个场景,场景就是 ...
- yii2.0缓存篇之页面缓存
页面缓存: 如果整个页面都不会发生改变,就可以使用页面缓存缓存整个页面. public function behaviors(){ //此方法[也叫行为]会提前控制器内其他方法执 ...
- windows上 python有多版本,如何管理,如何区别?
win10环境下: 1. where python 查看安装了哪些版本. 2.更改对应python.exe 文件的名称就能更改调用python的名称了. 3.不同python是两个完全独立的软件(独立 ...