POJ 3692:Kindergarten(最大的使命)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 4920 | Accepted: 2399 |
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
G, B (1 ≤ G, B ≤ 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
题意:幼儿园里男孩纸跟男孩纸认识,女孩纸跟女孩纸认识,男孩纸跟女孩纸也部分认识。
须要求出最大的,能使里面全部男孩纸女孩纸都认识的集合(最大团)
1.独立集:随意两点都不相连的顶点的集合
2.定理:最大独立集=顶点数-最大匹配边
3.全然子图:随意两点都相连的顶点的集合(最大全然子图即最大团)
4.定理:最大团=原图补图的最大独立集=顶点数-最大匹配数
注意,要反向建图(把认识的变成不认识的。不认识的成为认识的,这样才干求补图)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; const int M = 1000 + 5;
int k, m, n;
int link[M];
bool MAP[M][M];
bool cover[M];
int ans;
int cas=0; void init()
{
int x, y;
memset(MAP, true, sizeof(MAP));
for(int i=1; i<=k; i++)
{
scanf("%d%d", &x, &y);
MAP[x][y]=false;
}
} bool dfs(int x)
{
for(int y=1; y<=m; y++)
{
if(MAP[x][y] && !cover[y])
{
cover[y]=true;
if(!link[y] || dfs(link[y]))
{
link[y]=x;
return true;
}
}
}
return false;
} int main()
{
while(scanf("%d%d%d", &n, &m, &k) && n && m && k)
{
cas++;
ans=0;
init();
memset(link, false, sizeof(link));
for(int i=1; i<=n; i++)
{
memset(cover, 0, sizeof(cover));
if( dfs(i) )
ans++;
}
printf("Case %d: %d\n", cas,(n+m)-ans);
} return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
POJ 3692:Kindergarten(最大的使命)的更多相关文章
- POJ 3692 Kindergarten (二分图 最大团)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5660 Accepted: 2756 Desc ...
- POJ 3692 Kindergarten(最大团问题)
题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girl ...
- POJ 3692 Kindergarten(最大独立集)
[题目链接] http://poj.org/problem?id=3692 [题目大意] 男生相互之间都认识,女生相互之间也都认识, 一些男生和一些女生相互之间也认识,求找出最多的人参加派对, 他们相 ...
- poj 3692 Kindergarten (最大独立集)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4903 Accepted: 2387 Desc ...
- poj 3692 Kindergarten (最大独立集之逆匹配)
Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and al ...
- poj 3692 Kindergarten
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6956 Accepted: 3436 Desc ...
- POJ 3692 Kindergarten (补图是二分图的最大团问题)
题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...
- POJ 3692 Kindergarten(二分图最大独立集)
题意: 有G个女孩,B个男孩.女孩彼此互相认识,男孩也彼此互相认识.有M对男孩和女孩是认识的.分别是(g1,b1),.....(gm,bm). 现在老师要在这G+B个小孩中挑出一些人,条件是这些人都互 ...
- POJ 3692:Kindergarten 求补图的最大点独立集 头一次接触这样的做法
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5884 Accepted: 2877 Desc ...
随机推荐
- FPGA机器学习之学习的方向
经过了2个月对机器学习的了解后.我发现了,机器学习的方向多种多样.网页排序.语音识别,图像识别,推荐系统等.算法也多种多样.看见其它的书后,我发现除了讲到的k均值聚类.贝叶斯,神经网络,在线学习等等, ...
- 最近做RTSP流媒体的实时广播节目
//h264视频流打包代码 // NALDecoder.cpp : Defines the entry point for the console application. #include < ...
- Kafka设计
[Apache Kafka]Kafka设计 在开始开发producer和consumer之前,先从设计的角度看一看Kafka. 由于重度依赖JMS,且实现方式各异.对可伸缩架构的支持不够,Link ...
- web项目启动,运行方法
1.显示器(Listener) web文件加入 <listener> <listener-class>cn.ro.common.InitListener</li ...
- unity3d简单的相机跟随及视野旋转缩放
1.实现相机跟随主角运动 一种简单的方法是把Camera直接拖到Player下面作为Player的子物体,另一种方法是取得Camera与Player的偏移向量,并据此设置Camera位置,便能实现简单 ...
- 【转】c#引用类型与值类型的区别大盘点
解析:CLR支持两种类型:值类型和引用类型.用Jeffrey Richter(<CLR via C#>作者)的话来说,“不理解引用类型和值类型区别的程序员将会把代码引入诡异的陷阱和诸多性能 ...
- MAC随机修改批处理
原文:MAC随机修改批处理 @echo off mode con cols=70 lines=20 title MAC随机修改工具 color 3F setlocal enabledelayedexp ...
- __weak如何实现目标值自己主动设置nil的
在开始评论__weak机制之前,首先,一些床上用品 ARC 实现 苹果公司的官方介绍说,.ARC这是"内存管理由编译器"的,但事实上,只有编译器不能完全胜任,ARC另外还要看OC执 ...
- BZOJ 1096 ZJOI2007 仓库建设 边坡优化
标题效果:特定n植物,其中一些建筑仓库,有一点使,假设没有仓库仓库向右仓库.最低消费要求 非常easy边坡优化--在此之前刷坡优化的情况下,即使这道题怎么错过 订购f[i]作为i点建设化妆i花费所有安 ...
- AndroidUI的组成部分RoomButton
<!-- 知识点汇总: 1.Button与ImageButton的差别在于,Button生成的button上显示文字 而ImageButton上则显示图片.须要指出的是:为ImageButton ...