Kindergarten
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 5884   Accepted: 2877

Description

In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids to play a game, which need that all players
know each other. You are to help to find maximum number of kids the teacher can pick.

Input

The input consists of multiple test cases. Each test case starts with a line containing three integers

GB (1 ≤ GB ≤ 200) and M (0 ≤ M ≤ G × B), which is the number of girls, the number of boys and

the number of pairs of girl and boy who know each other, respectively.

Each of the following M lines contains two integers X and Y (1 ≤ X≤ G,1 ≤ Y ≤ B), which indicates that girl X and boy Y know each other.

The girls are numbered from 1 to G and the boys are numbered from 1 to B.

The last test case is followed by a line containing three zeros.

Output

For each test case, print a line containing the test case number( beginning with 1) followed by a integer which is the maximum number of kids the teacher can pick.

Sample Input

  1. 2 3 3
  2. 1 1
  3. 1 2
  4. 2 3
  5. 2 3 5
  6. 1 1
  7. 1 2
  8. 2 1
  9. 2 2
  10. 2 3
  11. 0 0 0

Sample Output

  1. Case 1: 3
  2. Case 2: 4

题意是幼儿园有很多小孩,男生和男生互相熟悉,女生和女生互相熟悉。然后给出了一些男生和一些女生互相熟悉的关系,要找到一个最大的群体,这个群体中所有人都互相熟悉,问这个群体最多多少人。

二分图的最大点独立集(二分图中两两互不相连的点的集合) = N - 二分图的最大匹配数量

这个题要求的点独立集是要两两互相连,所以这要求的是补图的最大点独立集。

代码:

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <vector>
  5. #include <string>
  6. #include <cstring>
  7. #pragma warning(disable:4996)
  8. using namespace std;
  9.  
  10. int grid[205][205];
  11. int link[205];
  12. int visit[205];
  13. int n,m,k,V1,V2;
  14. int result;
  15.  
  16. bool dfs(int x)
  17. {
  18. int i;
  19. for(i=1;i<=V2;i++)
  20. {
  21. if(grid[x][i]==0&&visit[i]==0)
  22. {
  23. visit[i]=1;
  24. if(link[i]==-1||dfs(link[i]))
  25. {
  26. link[i]=x;
  27. return true;
  28. }
  29. }
  30. }
  31. return false;
  32. }
  33.  
  34. void Magyarors()
  35. {
  36. int i;
  37.  
  38. result=0;
  39. memset(link,-1,sizeof(link));//!!这里不能是0
  40.  
  41. for(i=1;i<=V1;i++)
  42. {
  43. memset(visit,0,sizeof(visit));
  44. if(dfs(i))
  45. result++;
  46. }
  47. cout<<V1+V2-result<<endl;
  48. }
  49.  
  50. int main()
  51. {
  52. int i,j,pair,temp1,temp2;
  53.  
  54. for(i=1;;i++)
  55. {
  56. scanf("%d%d%d",&n,&m,&pair);
  57. V1=n;
  58. V2=m;
  59. if(n==0&&m==0&&pair==0)
  60. break;
  61.  
  62. cout<<"Case "<<i<<": ";
  63. memset(grid,0,sizeof(grid));
  64.  
  65. for(j=1;j<=pair;j++)
  66. {
  67. scanf("%d%d",&temp1,&temp2);
  68. grid[temp1][temp2]=1;
  69. }
  70. Magyarors();
  71. }
  72. return 0;
  73. }

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 3692:Kindergarten 求补图的最大点独立集 头一次接触这样的做法的更多相关文章

  1. POJ 3692 Kindergarten(最大团问题)

    题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girl ...

  2. POJ 3692 Kindergarten (补图是二分图的最大团问题)

    题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...

  3. POJ 3692 Kindergarten (二分图 最大团)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5660   Accepted: 2756 Desc ...

  4. POJ 3692 Kindergarten(最大独立集)

    [题目链接] http://poj.org/problem?id=3692 [题目大意] 男生相互之间都认识,女生相互之间也都认识, 一些男生和一些女生相互之间也认识,求找出最多的人参加派对, 他们相 ...

  5. poj 3692 Kindergarten (最大独立集)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4903   Accepted: 2387 Desc ...

  6. poj 3692 Kindergarten (最大独立集之逆匹配)

    Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and al ...

  7. poj 3692 Kindergarten

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6956   Accepted: 3436 Desc ...

  8. BZOJ1143:祭祀river(二分图求有向图的最大点独立集)

    在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都 会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成的网络.每条河道连接着 ...

  9. POJ 3692 Kindergarten(二分图最大独立集)

    题意: 有G个女孩,B个男孩.女孩彼此互相认识,男孩也彼此互相认识.有M对男孩和女孩是认识的.分别是(g1,b1),.....(gm,bm). 现在老师要在这G+B个小孩中挑出一些人,条件是这些人都互 ...

随机推荐

  1. redhat 7.6 apache 服务简单安装-01

    rpm -qa | grep httpd         //该命令查看apache是否安装,下面图片是已安装,未安装不会显示任何内容 yum install   httpd   -y        ...

  2. STP 指定端口 根端口 区别和理解

    不多说,先上图,A为指定端口,B为非指定端口. 看本文的网友应该知道根端口和指定端口的选举,但是对指定端口和根端口的理解不清楚.这里我就略过选举过程,直接描述这两者的区别和存在的意义. 指定端口:转发 ...

  3. 银行输入密码五次次数限制python程序实现

    python银行输入密码五次次数限制程序实现,主要在于对于异常情况的处理语句的编写,需要使用while循环语句和try和except异常处理语句的复合编写语句n=0while n<5: try: ...

  4. redis之Set(无序)类型常用方法总结

    redis之Set(无序)类型常用方法总结 存--sadd key member [member ...] 取--SMEMBERS key sadd key member [member ...] 向 ...

  5. change事件和input事件的区别

    input事件: input事件在输入框输入的时候回实时响应并触发 change事件: change事件在input失去焦点才会考虑触发,它的缺点是无法实时响应.与blur事件有着相似的功能,但与bl ...

  6. IDEA配置数据库连接失败的问题

    今天采用IDEA连接数据库失败了,有几个问题需要注意 首先笔者采用的数据库版本为8.0.17而IDEA自带版本是5.2.26大概,于是首先出现的问题是驱动不匹配,那么就需要换成我自己的版本,配置如下 ...

  7. 一个前端博主的nginx+php+mysql的环境搭建

    这几天天某的公司给了在下一个需求,让我修改一个后端大佬用PHP写的一个官网,虽然说修改的内容还是很简单,但是毕竟之前还是没接触过PHP,于是开始了漫长的爬坑之旅,话不多说,这次就给大家介绍一下我配置安 ...

  8. 【拒绝挂分】盘点蒟蒻ghy的各种sb错误

    1.m与n打反(打错) NOIPd2t2 50变15爽不爽啊.jpg 某次信心赛四道sb题里面最sb的一道 sort里面的m打成n 100变40爽不爽啊.jpg(还有40我真的谢谢您了 2.没开lon ...

  9. priority_queue优先级队列总结

    http://www.cppblog.com/Darren/archive/2009/06/09/87224.html priority_queue用法 priority_queue 调用 STL里面 ...

  10. 图解jvm--(一)jvm内存结构

    jvm内存结构 1.程序计数器 1.1 定义 Program Counter Register 程序计数器(寄存器) 作用,记住下一条jvm指令的执行地址 特点 是线程私有的 (唯一)不会存在内存溢出 ...