Girls and Boys

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

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
 
题意:找到所有无缘分的人有多少?
题解:最大点独立集 = 顶点数 - 最大匹配数,但是0-4,4-0连了两次,所以最大匹配要除二.
我对这种两边都是同一集合元素然后做二分图匹配的题目的看法就是:要连双向边,然后最大匹配数要除以二。
但是这题不要连双向边,因为它给的条件是对称的。
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
using namespace std;
const int N = ;
int graph[N][N];
bool vis[N];
int linker[N],n;
bool dfs(int u){
for(int i=;i<n;i++){
if(graph[u][i]&&!vis[i]){
vis[i] = true;
if(linker[i]==-||dfs(linker[i])){
linker[i] = u;
return true;
}
}
}
return false;
}
int main()
{
while(scanf("%d",&n)!=EOF){
for(int i=;i<n;i++){
for(int j=;j<n;j++)
graph[i][j] = ;
}
for(int i=;i<n;i++){
int u,v,num;
scanf("%d: (%d)",&u,&num);
for(int j=;j<num;j++){
scanf("%d",&v);
graph[u][v] = ;
}
}
int ans = ;
memset(linker,-,sizeof(linker));
for(int i=;i<n;i++){
memset(vis,false,sizeof(vis));
if(dfs(i)) ans++;
}
printf("%d\n",n-ans/);
}
return ;
}

hdu 1068(最大独立集)的更多相关文章

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

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

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 有n个同学,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合 ...

  3. HDU 1068 Girls and Boys(最大独立集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 题目大意:有n个人,一些人认识另外一些人,选取一个集合,使得集合里的每个人都互相不认识,求该集合 ...

  4. hdu - 1068 Girls and Boys (二分图最大独立集+拆点)

    http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...

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

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

  6. HDU ACM 1068 最大独立集

    意甲冠军:n同学.有些学生将有宿命的男性和女性成为恋人.收集注定要成为爱好者求学生的最大数目不存在. 分析:独立设置,顶点设定图的一个子集,在休闲2不连续: 二分图:最大独立集 = 顶点 - 匹配的最 ...

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

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

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

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

  9. hdu 1068 Girls and Boys(匈牙利算法求最大独立集)

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

随机推荐

  1. IDEA运行lambda表达式

    在idea写了一个lambda的测试例子,但是运行一直报错, public class LambdaTest { public static void main(String[] args) { ne ...

  2. 一个简单的NetCore项目:1 - 搭建框架,生成数据库

    1- 启动项目 安装.NETCORE SDK,教程在网上可以搜索的到,这里就不讲述了.简单粗暴的方式就是安装最新的VS2015. 2-搭建框架 2.1 打开VS新建一个项目,在弹出的新建项目对话框中, ...

  3. Java作业09-异常

    6. 为如下代码加上异常处理 byte[] content = null; FileInputStream fis = new FileInputStream("testfis.txt&qu ...

  4. Mybatis学习系列(七)缓存机制

    Mybatis缓存介绍 MyBatis提供一级缓存和二级缓存机制. 一级缓存是Sqlsession级别的缓存,Sqlsession类的实例对象中有一个hashmap用于缓存数据.不同的Sqlsessi ...

  5. To Chromium之浏览器外框UI

    先不去管那些webkit,V8 engine, Parser, security,IPC... 先来看看Chromium的外框UI是那些code负责的,如果自己可以定制化一下,应该蛮好玩的. TBD. ...

  6. C++ 点

    2017/12/23 scoped_ptr类型的指针,只能在一个namespace中使用 1) 怎么查看元素在set中是否存在 1) istringstream类用于执行C++风格的串流的输入操作. ...

  7. setCharacterEncoding 是在request.getParameter获取参数之前 设置request的编码格式 一步到位

    setCharacterEncoding 是在request.getParameter获取参数之前 设置request的编码格式 一步到位

  8. [51nod1503]猪和回文 DP

    ---题面--- 题解: 首先观察到题目要求的是合法回文串的个数,而回文串要求从前往后和从后往前是一样的,因此我们假设有两只猪,分别从左上和右下开始走,走相同的步数最后相遇,那么它们走的路能拼在一起构 ...

  9. How do I use EC2 Systems Manager to join an instance to my AWS Directory Service domain?

    1. Create new role "EC2RoleforSSM" in AWS IAM AWS->IAM->Roles->Create role->Se ...

  10. Java中中英文对齐输出问题,以及Java中的格式化输出

    一 中英文对齐输出问题 问题,要求控制台输出如下: abcefg  def 森林 阿狗 其实就是要求对齐输出,各种查找java的格式化输出,然后发现只要一个简单的“\t”就可以实现. 代码如下: Sy ...