Girls and Boys

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3260    Accepted Submission(s): 1405

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
 
题意:求最大独立集
思路:二分图匹配
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<stack>
#include<cstdlib>
#include <vector>
#include<queue>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e3+; int pre[maxn];
bool map[maxn][maxn],used[maxn];
int n; int dfs(int u)
{
for(int v = ;v < n; v++)
{
if(map[u][v] && used[v] == false)
{
used[v] = true;
if(pre[v] == - || dfs(pre[v]))
{
pre[v] = u;
return true;
}
}
}
return false;
}
int main()
{
while(~scanf("%d", &n))
{
memset(map,false,sizeof map);
memset(pre,-,sizeof pre);
for(int i=;i<n;i++)
{
int k,num;
scanf("%d: (%d)",&k,&num);
for(int j=;j<num;j++)
{
int r;
scanf("%d",&r);
map[k][r] = true;
}
}
int sum = ;
for(int i = ; i < n; i++)
{
memset(used,false,sizeof used);
if(dfs(i))
sum++;
}
sum /= ;
printf("%d\n",n-sum);
}
}
 

Girls and Boys-hdu 1068的更多相关文章

  1. Girls and Boys HDU - 1068 二分图匹配(匈牙利)+最大独立集证明

    最大独立集证明参考:https://blog.csdn.net/qq_34564984/article/details/52778763 最大独立集证明: 上图,我们用两个红色的点覆盖了所有边.我们证 ...

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

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

  3. HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)

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

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

  8. hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】

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

  9. (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 ...

  10. Hdu 1068 最小路径覆盖

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

随机推荐

  1. 《从0到1学习Flink》—— Flink 中几种 Time 详解

    前言 Flink 在流程序中支持不同的 Time 概念,就比如有 Processing Time.Event Time 和 Ingestion Time. 下面我们一起来看看这几个 Time: Pro ...

  2. Xcode Ghost

    Xcode Ghost,是一种手机病毒,主要通过非官方下载的 Xcode 传播,能够在开发过程中通过 CoreService 库文件进行感染,使编译出的 App 被注入第三方的代码,向指定网站上传用户 ...

  3. AngularJS(十):依赖注入

    本文也同步发表在我的公众号“我的天空” 依赖注入 依赖注入不是AngularJS独有的概念,而是现代软件开发与架构的范畴,但是在AngularJS中“依赖注入”是其核心思想之一,所以我们专门来学习一下 ...

  4. linux服务器安装nodejs运行环境

    安装nodejs运行环境 第一步:到node官网下载相应版本的安装包,将安装包放置服务器上,路径为 usr/local/node(可根据自身情况进行修改) 第二步:解压 ***.tar.xz格式文件需 ...

  5. Mac 颜色取值

    command+shift+4  截图,我靠,我以前不知道 系统自带数码测色计, 选择显示十六位制 command+L 锁定 command+shift+c 复制 简直太方便

  6. 【iOS学习笔记】改变状态栏字体颜色

    Step1. info.plist中设置UIViewControllerBasedStatusBarAppearance为NO Step2. AppDelegate.m中添加 - (BOOL)appl ...

  7. log4j-初识

    1.配置文件介绍: 1.1. 控制台输出:log4j.rootLogger=DEBUG, Console ,File #Console log4j.appender.Console=org.apach ...

  8. hive 报错FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient FAILED: Execu

    使用hive一段时间以后,今天在使用的时候突然报错,如下: hive> show databases;FAILED: Error in metadata: java.lang.RuntimeEx ...

  9. [VC]strcpy和strncoy的区别

    第一种情况:char* p="how are you ?";char name[20]="ABCDEFGHIJKLMNOPQRS"; strcpy(name,p ...

  10. IOS 绘制图片水印(封装)

    - (void)viewDidLoad { [super viewDidLoad]; // -1.加载图片 // UIImage *image = [UIImage imageNamed:@" ...