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. lintcode-109-数字三角形

    109-数字三角形 给定一个数字三角形,找到从顶部到底部的最小路径和.每一步可以移动到下面一行的相邻数字上. 注意事项 如果你只用额外空间复杂度O(n)的条件下完成可以获得加分,其中n是数字三角形的总 ...

  2. P3539 [POI2012]ROZ-Fibonacci Representation

    题目描述 The Fibonacci sequence is a sequence of integers, called Fibonacci numbers, defined as follows: ...

  3. shared_ptr 的循环依赖问题

    #include <memory> #include <iostream> using namespace std; struct A; struct B; struct A ...

  4. [洛谷P1131][ZJOI2007]时态同步

    题目大意:给你一棵树,每条边有边权,要求增加一些边的边权,使得根节点到每个叶子节点的距离相等,求出最少共增加多少边权. 题解:树形$DP$,对于每个点,如果它到它的子树中的叶子节点距离不同,一定要在这 ...

  5. [CF620E]New Year Tree

    题目大意:有一棵以$1$为根的有根树,有$n$个点,每个节点初始有颜色$c_i$.有两种操作: $1 v c:$将以$v$为根的子树中所有点颜色更改为$c$ $2 v:$ 查询以$v$为根的子树中的节 ...

  6. Visio中ShapeAdded和SelectionAdded

    SelectionAdded 和 ShapeAdded 事件的相似之处在于它们都在创建形状之后触发.它们的区别在于,当单个操作添加多个形状时它们的行为方式不同.假定一个 Paste 操作创建三个新建形 ...

  7. 【BZOI 1202 狡猾的商人】

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4149  Solved: 1994[Submit][Status][Discuss] Descript ...

  8. JavaScript的大括号的语义

    Javascript中大括号"{}"有四种语义作用: 语义1. 组织复合语句,这是最常见的: view source   print? 1 if( condition ) { 2 ...

  9. git使用笔记(七)版本回退和撤销

    By francis_hao    Nov 21,2016 从版本库初始化开始,每一步的撤销操作 添加第一个文件 在空的版本库中创建了一个文件并git add到了缓存区,这时候怎么撤销呢? 撤销单个文 ...

  10. 定时导出用户数据(expdp,impdp)

    一 定时导出数据: #!/bin/bash############################################################################### ...