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. redhat 7.6 安装 inotify-tools 文件监控工具 搭配rsync

    1.解压inotify-tools tar -zxvpf inotify-tools-3.14.tar.gz 2.cd 到解压的目录 3../configure  编译,然后失败,提示checking ...

  2. 设计模式课程 设计模式精讲 20-2 解释器模式coding

    1 代码演练 1.1 代码演练1(解释器模式coding) 1.2 代码演练如何应用了解释器模式 1 代码演练 1.1 代码演练1(解释器模式coding)(该案例运用了栈的先进先出的特性) 需求: ...

  3. 设计模式课程 设计模式精讲 8-2 单例设计模式-懒汉式及多线程Debug实战

    1 主要内容 1.1 多线程debug 1.2 synchronized同步锁的调用 1.3 懒加载的应用 2 代码演练 2.1 单线程调用 2.2 多线程调用 2.3 锁的调用 1 主要内容 1.1 ...

  4. Hive的存储和MapReduce处理——数据清洗(Part2)

    日期:2019.11.14 博客期:116 星期四 基本的处理类 import java.sql.Connection; import java.sql.DriverManager; import j ...

  5. eclispe+maven+ssm+sql_server/mysql配置

    链接: https://pan.baidu.com/s/1_BFI8XfS8l89-3-1IjlVZg 密码: x9in

  6. centos安装出现dracut-initqueue timeout错误

    dracut:/# cd /dev dracut:/# ls 这样子你就会看到所有的设备信息. 找到sda4,  不一定是sda4,有可能是其他的,实在不确定就拔了优盘看一下哪个消失了 dracut: ...

  7. topthink/think-swoole 扩展包的使用 之 Task

    本想自己适配的,奈何keng貌似不少,所以果断选择官方提供的包来适配233... 默认条件:thinkphp5.1.*版本下,且安装了swoole扩展 主要演示:task 任务的投递 友情提示:在sw ...

  8. C#委托-事件示例

    Program.cs using System;using System.Collections.Generic;using System.Linq;using System.Text;using S ...

  9. Keras入门——(4)长短期记忆网络LSTM(一)

    参考: https://blog.csdn.net/zwqjoy/article/details/80493341 https://blog.csdn.net/u012735708/article/d ...

  10. 第二章:windows下搭建开发环境

    IDE ---- pycharm数据库 --- mysql.redis.elasticsearch开发环境 -- anaconda 第一节:pycharm的安装和简单使用...(网上一搜一大堆,所以没 ...