hdoj--1068--Girls and Boys(最大独立集)
Girls and Boys
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.
The input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description:
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, for n subjects.
For each given data set, the program should write to standard output a line containing the result.
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
5
2
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>map[2000];
int used[2000],pipei[2000];
int find(int x)
{
for(int i=0;i<map[x].size();i++)
{
int y=map[x][i];
if(!used[y])
{
used[y]=1;
if(!pipei[y]||find(pipei[y]))
{
pipei[y]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(pipei,0,sizeof(pipei));
for(int i=0;i<n;i++)
{
map[i].clear();
int a,b,t;
scanf("%d: (%d)",&a,&t);
while(t--)
{
scanf("%d",&b);
map[a].push_back(b);
}
}
int sum=0;
for(int i=0;i<n;i++)
{
memset(used,0,sizeof(used));
sum+=find(i);
}
printf("%d\n",n-sum/2);
}
return 0;
}
hdoj--1068--Girls and Boys(最大独立集)的更多相关文章
- hdoj 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 BoysTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 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) ...
- 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) ...
- 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 题目大意:有n个人,一些人认识另外一些人,选取一个集合,使得集合里的每个人都互相不认识,求该集合 ...
- hdu - 1068 Girls and Boys (二分图最大独立集+拆点)
http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...
随机推荐
- Redmine使用指南
公司之前使用JIRA登bug,但是客户在美国,他们习惯于用Redmine登bug,所以我们也开始在Redmine登bug,找来一个比较全面的Redmine使用指南,不懂时直接查看. http://bl ...
- 转:Fiddler抓包工具总结
http://www.cnblogs.com/yyhh/p/5140852.html#l02
- [Advanced Algorithm] - Symmetric Difference
题目 创建一个函数,接受两个或多个数组,返回所给数组的 对等差分(symmetric difference) (△ or ⊕)数组. 给出两个集合 (如集合 A = {1, 2, 3}和集合 B = ...
- React Native - 使用Vibration API实现设备振动
有时程序中需要实现这样的功能,当有重要的消息提醒时,我们会发出声音告知用户.而如果用户关闭了声音,那么就可以改用振动来提醒用户. 使用 React Native 提供的 Vibration API,我 ...
- Apex语言(三)原始数据类型
1.原始数据类型(Primitive) 整数:Integer 双精度:Double 单精度:Decimal 长整型:Long 日期:Date 日期时间:Datetime 字符串:String ID:I ...
- python tips:dict的key顺序
python3.6+版本中,dict的键值保持插入有序. t = list(range(10)) b = t[:] d = dict(zip(t, b)) print(list(d.items())) ...
- 3D模型在UI上显示的方法(Unity)
方法:使用RawImage通过Render Texter将摄像机下的物体渲染纹理记录并显示在RawImage上面 具体实现:新建一个模型(Cube),新建一个摄像机,将Clear Flags设置为So ...
- 【剑指Offer】56、删除链表中重复的结点
题目描述: 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. 例如,链表1->2->3->3->4->4-> ...
- Codeforces Round #406 (Div. 2) 787-D. Legacy
Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So ...
- 复习C语言基础知识(day02)
一.大型软件组织 定义规则,规则就是协议.用户和中介的接口. 软件开发的过程: 定义规则,定义协议.软件为用户提供的功能. 在C语言中使用接口实现.接口就是函数. 两种用户 函数的使用者 函数的实现者 ...