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()/);
}
}

最新文章

  1. 15个实用的jQuery代码片
  2. POJ 1236 SCC+缩点
  3. android中5大布局
  4. 深入浅出 React Native:使用 JavaScript 构建原生应用
  5. 领域驱动设计和实践(转:http://kb.cnblogs.com/page/112298/)
  6. compass sprite
  7. poj 1430 第二类斯特林数
  8. 操作系统学习笔记_12_I/O管理 --I/O管理概述
  9. HDU 1251 统计拼图 Trie解决问题的方法
  10. zoj 2913 Bus Pass
  11. POJ 1182 食物链 经典并查集+关系向量简单介绍
  12. 如何利用fis3来模拟后台返回数据
  13. 补写:Best Coder #85 1001 Sum(前缀和)
  14. 为什么MIP-Cache存在
  15. TCP/IP HTPP
  16. BZOJ 1269 文本编辑器editor(伸展树)
  17. Log4j 随笔
  18. LeetCode 151 翻转字符串里的单词
  19. 学以致用六---Centos7.2+python3.6.2+django2.1.1 --搭建一个网站
  20. ld链接器的工作原理及链接顺序(转)

热门文章

  1. Unity3D占用内存太大的解决方法
  2. C语言register关键字—最快的关键字 ---------------转自http://blog.sina.com.cn/s/blog_6a1837e90101128k.html
  3. gmm
  4. 我常用的delphi 第三方控件
  5. 能用Shell就别编程-海量文本型数据的处理
  6. Linux命令之exit - 退出当前shell【返回值状态】
  7. Git SSH Key 生成步骤
  8. Gson简要使用
  9. iOS 使用UIWebView把oc代码和javascript相关联
  10. Windows下配置Apache服务器并支持php