Girls and Boys
Girls and Boys
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5565 Accepted Submission(s): 2481
Problem Description
the second year of the university somebody started a study on the romantic relations between the students. The relation “romantically involved” is defined between one girl and one boy. For the study 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.
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.
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
Southeastern Europe 2000
Recommend
JGShining
嗯,看起来是个求最大独立集的题,而且还是个二分图.因为题里没说有Homosexuality,所以不会有奇环.不过图是用一般形式给出的算出来的匹配要除以2.
#include<stdio.h>
#include<string.h>
int n,m,match[];
bool visit[],G[][];
bool DFS(int k)
{
int t;
for (int i=;i<m;i++)
if (G[k][i] && !visit[i])
{
visit[i]=;
t=match[i];
match[i]=k;
if (t==- || DFS(t)) return true;
match[i]=t;
}
return false;
}
int Max_match()
{
int ans=;
memset(match,-,sizeof(match));
for (int i=;i<n;i++)
{
memset(visit,,sizeof(visit));
if (DFS(i)) ans++;
}
return ans;
}
int main()
{
int t,a,b,c;
while (scanf("%d",&t)!=EOF)
{
n=m=t;
memset(G,,sizeof(G));
while (t--)
{
scanf("%d: (%d)",&a,&b);
for (int i=;i<b;i++)
{
scanf("%d",&c);
G[a][c]=;
}
}
printf("%d\n",n-Max_match()/);
}
}
Girls and Boys的更多相关文章
- POJ 1466 Girls and Boys
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- hduoj-----(1068)Girls and Boys(二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ Girls and Boys (最大独立点集)
Girls and Boys Time Limit: 5000MS Memo ...
- poj 1466 Girls and Boys(二分图的最大独立集)
http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submis ...
- hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 网络流(最大独立点集):POJ 1466 Girls and Boys
Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...
- Girls and Boys(匈牙利)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- (hdu step 6.3.2)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) ...
随机推荐
- Mysql跨平台(Windows,Linux,Mac)使用与安装
MySQL其实是一个跨平台的轻量级数据库,平时开发会用到很多.有写程序可能要跨平台开发,接下来我就介绍一下如何跨平台使用Mysql. 这里所谓的跨平台就是Windows,Linux,Mac共同用一套M ...
- Linux下读取默认MAC地址
导读MAC(Media Access Control,介质访问控制)计算机通过它来定义并识别网络设备的位置.在嵌入式linux学习中不可避免也会遇到MAC,本文主要描述了如何通过操作OTP来读取嵌入式 ...
- ruby on rails揭开route路由的真面目
文章是从我的个人主页上粘贴过来的, 大家也可以访问我的主页 www.iwangzheng.com 最近的项目里发现一个问题,大师和pp写的index页面就好使,我写index页面就不往index页面跳 ...
- openstack 前期准备工作
OS 是 centos6.5_X86_64 一.vmware 虚拟机 准备两台机虚拟机即可 二.导入第三方安装源 [root@openstack ~]# rpm -Uvh http://dl.fedo ...
- MyBatis调用存储过程
MySQL存储过程 DROP PROCEDURE IF EXISTS transferMoney; -- 实现转账功能的存储过程 CREATE PROCEDURE transferMoney ( IN ...
- 【ERROR】使用jquery的ajax出现error:readyState=4,status=500
使用jquery的ajax出现error:readyState=4,status=500,ajax代码如下: $.ajax({ url : "../toBeFinMisManage/show ...
- mysql in 子查询 效率慢 优化(转)
mysql in 子查询 效率慢 优化(转) 现在的CMS系统.博客系统.BBS等都喜欢使用标签tag作交叉链接,因此我也尝鲜用了下.但用了后发现我想查询某个tag的文章列表时速度很慢,达到5秒之久! ...
- linux 学习一:安装jdk和tomcat
使用secureCRT 一.首先安装centos的rzsz. 1.yum自动安装:(yum安装rzsz) yum install lrzsz 2.手动安装方法如下:(包有问题,还是采用第一种方式) 2 ...
- host
#Google Services START209.116.186.241 0.docs.google.com209.116.186.241 0.drive.google.com209.116.186 ...
- swift init继承问题
当在子类的 designated init方法中不手动调用 父类的 designated init方法时,如果父类有不接受任何参数的init,那么系统会自动调用它,编译器不会报错.但是如果父类中没有不 ...