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

2 3 3
1 1
1 2
2 3
2 3 5
1 1
1 2
2 1
2 2
2 3
0 0 0

Sample Output

Case 1: 3
Case 2: 4

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

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

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

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int grid[205][205];
int link[205];
int visit[205];
int n,m,k,V1,V2;
int result; bool dfs(int x)
{
int i;
for(i=1;i<=V2;i++)
{
if(grid[x][i]==0&&visit[i]==0)
{
visit[i]=1;
if(link[i]==-1||dfs(link[i]))
{
link[i]=x;
return true;
}
}
}
return false;
} void Magyarors()
{
int i; result=0;
memset(link,-1,sizeof(link));//!!这里不能是0 for(i=1;i<=V1;i++)
{
memset(visit,0,sizeof(visit));
if(dfs(i))
result++;
}
cout<<V1+V2-result<<endl;
} int main()
{
int i,j,pair,temp1,temp2; for(i=1;;i++)
{
scanf("%d%d%d",&n,&m,&pair);
V1=n;
V2=m;
if(n==0&&m==0&&pair==0)
break; cout<<"Case "<<i<<": ";
memset(grid,0,sizeof(grid)); for(j=1;j<=pair;j++)
{
scanf("%d%d",&temp1,&temp2);
grid[temp1][temp2]=1;
}
Magyarors();
}
return 0;
}

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

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. android 简单列表对话框(AlertDialog.Builder().setItems())

    ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ...

  2. 三、linux基础-常用命令man_cd_|_find_ln_>_history

    3通用命令3.1 man命令man pwd      来查看该命令的全部帮助手册备注:命令最终是在内核中执行的,但是内核并无法直接识别,所以先通过shell执行,然后再交给内核执行3.2 cd 命令c ...

  3. Keepalived+Nginx解决方案实现高可用的API网关(nginx)

    一. 采用Keepalived+Nginx解决方案实现高可用的API网关. 2.1 Nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP ...

  4. FFmpeg——AVCodec,AVCodecContext,AVCodecParameters 辨析

    先贴上雷神的一张FFmpeg关键结构体之间的关系图: 再看雷神的分析: 每个AVStream存储一个视频/音频流的相关数据: 每个AVStream对应一个AVCodecContext,存储该视频/音频 ...

  5. 「NOI2015」软件包管理器

    题目描述 题面比较啰唆,我先把大体意思讲一下: 首先,有编号从\(0\)到\(N-1\)的\(N\)个节点,根节点一定是\(0\)号节点(无前驱) (我把下标都加上了一,转化为以\(1\)为起始下标的 ...

  6. Autoit里用多进程模拟多线程

      一直以来Autoit都不支持多线程,因此一些需要同时运行多个循环的操作也就无法实现.这个问题在其它的某些语言里也经常出现,解决的方法就是使用多进程. 所谓多进程,就是同时运行多个子进程,每个子进程 ...

  7. python如何画三维图像?

    python三维图像输出的代码如下所示:#画3D函数图像输出from mpl_toolkits.mplot3d import Axes3Dfrom matplotlib import cmimport ...

  8. eclipse js文件无法保存错误

    错误信息如下 Save Failedjdk.nashorn.internal.runtime.ECMAException.getEcmaError()Ljava/lang/Object; 网上多番查找 ...

  9. JDBC--处理事务

    1.事务是指一组逻辑操作单元,使数据从一种状态转换到另一种状态. 2.事务的四个属性: --1)原子性:事务是一个不可分割的工作单位,事务中的操作要么都发生要么都不发生: --2)一致性:事务必须是数 ...

  10. 常用mac/unix/linux命令

    1.查询ip地址 ifconfig 2.查找服务器上应用程序的端口分配 grep telnet /etc/services (telnet) telnet使用TCP/UDP端口号23 grep dom ...