Girls and Boys

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

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
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:  1281 1507 1528 1054 2063
 
 
 
/*
题意:n个同学,一些男女同学会有缘分成为情侣,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合中不存在有缘成为情侣的同学的最大同学数。
题解:
独立集:图的顶点集的子集,其中任意两点不相邻
最大独立集 = 顶点数 - 最大匹配数
由于本题是从整个点集搜索,并不是将点集分开成(A)(B),(1->2)(2->1)对称存在,所以相当于搜索了两遍。因此真正最大匹配数等于最大匹配数/2.
具体我也不明白其中的原理,只是理解。
*/
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = ;
bool vis[maxn]; //查询右集合中的点有没有被访问过
int link[maxn]; //link[i]表示右集合中的i点是由左集合中的哪个点连接的
int G[maxn][maxn]; //邻接矩阵
int tx,ty; //左右集合的点的个数
bool find(int u) //用来寻找增广路
{
for(int i = ; i < ty; i++) //遍历右集合中的每个点
{
if(!vis[i] && G[u][i]) //没有被访问过并且和u点有边相连
{
vis[i] = true; //标记该点
if(link[i] == - || find(link[i]))
{
//该点是增广路的末端或者是通过这个点可以找到一条增广路
link[i] = u;//更新增广路 奇偶倒置
return true;//表示找到一条增广路
}
}
}
return false;
} int solve()
{
int num1 = ;
memset(link, -, sizeof(link));//初始化为-1表示 不与左集合中的任何元素有link
for(int i = ; i < tx; i++) //遍历左集合
{
memset(vis, false, sizeof(vis));//每一次都需要清除标记
if(find(i))
num1++;//找到一条增广路便num++
}
return num1;
}
int main()
{
int a,b,c;
int cases;
while(scanf("%d",&cases)!=EOF)
{
tx=cases;
ty=cases;
memset(G,,sizeof(G));
while(cases--)
{
scanf("%d: (%d)",&a,&b);
for(int i=;i<b;i++)
{
scanf("%d",&c);
G[a][c]=;
}
}
printf("%d\n",tx-solve()/);
}
return ;
}
/*int main()
{ int z1,zn,p;
while(scanf("%d",&x_cnt)!=EOF)
{
y_cnt=x_cnt;
int tt=x_cnt;
memset(G,0,sizeof(G)); while(tt--)
{
scanf("%d: (%d)",&z1,&zn);
for(int j=1; j<=zn; j++)
{
scanf("%d",&p);
G[z1][p]=1;
} printf("%d\n",x_cnt-solve()/2);
} }
return 0;
}*/

HDU1068 最大独立点集的更多相关文章

  1. POJ Girls and Boys (最大独立点集)

                                                                Girls and Boys Time Limit: 5000MS   Memo ...

  2. hdu 1068 Girls and Boys 最大独立点集 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 思路: 求一集合满足,两两之间没有恋爱关系 思路: 最大独立点集=顶点数-最大匹配数 这里给出的 ...

  3. Hdu3829 Cat VS Dog(最大独立点集)

    Cat VS Dog Problem Description The zoo have N cats and M dogs, today there are P children visiting t ...

  4. 洛谷 - P2774 - 方格取数问题 - 二分图最大独立点集 - 最小割

    https://www.luogu.org/problemnew/show/P2774 把两个相邻的节点连边,这些边就是要方便最小割割断其他边存在的,容量无穷. 这种类似的问题的话,把二分图的一部分( ...

  5. 最大独立点集&最小点覆盖

    1.最大独立点集: 在二分图中,选最多的点,使得任意两个点之间没有直接边连接. 最大独立集= 最小边覆盖 = 总点数- 最大匹配 (条件:在二分图中) 2.最小边覆盖: 在二分图中,求最少的边,使得他 ...

  6. COCI2014/2015 Contest#1 D MAFIJA【基环树最大独立点集】

    T1725 天黑请闭眼 Online Judge:COCI2014/2015 Contest#1 D MAFIJA(原题) Label:基环树,断环+树形Dp,贪心+拓扑 题目描述 最近天黑请闭眼在 ...

  7. 图论(二分图最大权独立点集):COGS 2051. 王者之剑

    2051. 王者之剑 ★★★☆   输入文件:Excalibur.in   输出文件:Excalibur.out   简单对比 时间限制:1 s   内存限制:256 MB [题目描述] 这是在阿尔托 ...

  8. 网络流(最大独立点集):POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...

  9. hdu 3829 Cat VS Dog 二分匹配 最大独立点集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3829 题目大意: 给定N个猫,M个狗,P个小朋友,每个小朋友都有喜欢或者不喜欢的某猫或者某狗 管理员从 ...

随机推荐

  1. Spring 事务配置管理,简单易懂,详细 [声明式]

    Spring 事务配置说明 Spring 如果没有特殊说明,一般指是跟数据存储有关的数据操作事务操作:对于数据持久操作的事务配置,一般有三个对象,数据源,事务管理器,以及事务代理机制: Spring ...

  2. [代码片段]javascript检查图片大小和格式

    function checkImgType(input) { var this_ = document.getElementsByName('imgFile')[0]; var filepath = ...

  3. 每天一个linux命令(51):rcp命令

    rcp代表“remote file copy”(远程文件拷贝).该命令用于在计算机之间拷贝文件.rcp命令有两种格式.第一种格式用于文件到文件的拷贝:第二种格式用于把文件或目录拷贝到另一个目录中. 1 ...

  4. Journey Of Code组组员贡献率

    628是该组的组长,前期的主要任务是数据库的设计,中后期加入实现功能模块的工作,实现了文件的上传和解析excel表格的功能,负责协调组员之间的工作和沟通,并且也是最后上台进行演示的人员:所以贡献率有3 ...

  5. 搭建OpenWrt开发环境(包括编译过程)

    OpenWrt是一个高度模块化.高度自动化的嵌入式linux发行版,其编译和安装过程比普通的linux发行版而言,要简单太多了.如果您是新手,您那恐惧的心大可放到肚子里,呵呵.对于新手来说最麻烦的恐怕 ...

  6. 【POJ 3320】Jessica's Reading Problemc(尺取法)

    题 题意 P个数,求最短的一段包含P个数里所有出现过的数的区间. 分析 尺取法,边读边记录每个数出现次数num[d[i]],和不同数字个数n个. 尺取时,l和r 代表区间两边,每次r++时,d[r]即 ...

  7. 【CodeForces 611C】New Year and Domino

    题 题意 h行w列的矩形格子,“." 代表空的,"#" 代表满的,多米诺是 1*2 的长方体,现在放进格子,给你子矩形的左上角和右上角,问在子矩形里共有多少种放一块多米诺 ...

  8. bzoj 3437 斜率优化DP

    写题解之前首先要感谢妹子. 比较容易的斜率DP,设sum[i]=Σb[j],sum_[i]=Σb[j]*j,w[i]为第i个建立,前i个的代价. 那么就可以转移了. /**************** ...

  9. BZOJ 3110 [Zjoi2013]K大数查询

    Description 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c 如果是2 a b c形式,表示询问从第a个位置到第b个位 ...

  10. Laravel 5 中的配置

    介绍 Laravel 的所有的配置文件都放在了 config 这个目录的下面.每个选项都有介绍. config├── app.php├── auth.php├── cache.php├── compi ...