POJ 3692: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
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
题意是幼儿园有很多小孩,男生和男生互相熟悉,女生和女生互相熟悉。然后给出了一些男生和一些女生互相熟悉的关系,要找到一个最大的群体,这个群体中所有人都互相熟悉,问这个群体最多多少人。
二分图的最大点独立集(二分图中两两互不相连的点的集合) = 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 求补图的最大点独立集 头一次接触这样的做法的更多相关文章
- POJ 3692 Kindergarten(最大团问题)
题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girl ...
- POJ 3692 Kindergarten (补图是二分图的最大团问题)
题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...
- 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 [题目大意] 男生相互之间都认识,女生相互之间也都认识, 一些男生和一些女生相互之间也认识,求找出最多的人参加派对, 他们相 ...
- 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 ...
- BZOJ1143:祭祀river(二分图求有向图的最大点独立集)
在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都 会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成的网络.每条河道连接着 ...
- POJ 3692 Kindergarten(二分图最大独立集)
题意: 有G个女孩,B个男孩.女孩彼此互相认识,男孩也彼此互相认识.有M对男孩和女孩是认识的.分别是(g1,b1),.....(gm,bm). 现在老师要在这G+B个小孩中挑出一些人,条件是这些人都互 ...
随机推荐
- 学习不一样的vue4:mock与axios实战1
学习不一样的vue4:mock与axios实战1 发表于 2017-06-14 | 分类于 web前端| | 阅读次数 8180 首先 首发博客: 我的博客 项目源码: 源码(喜欢请star) ...
- 使用eclipse创建一个简单的Java Web应用程序
关于Java JDK/JRE.Tomcat的配置等等都没什么好说的,主要记录一下使用Eclipse创建web工程时的一些点以及说一说自己用IDEA的创建失败的过程(IDEA没运行成功...暂时不想弄了 ...
- Python 基础之面向对象初识与类的封装
一.面向对象类的初识 1.类的定义 #三种方式:#1.class MyClass: pass #2.推荐class MyClass(): pass #3.class MyClass(obj ...
- 强制设置双缓冲DoubleBuffered 解决tableLayoutPanel 闪烁
tableLayoutPanel.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.In ...
- 最新获取SkyDrive音乐外链mp3地址方法20131003
最新获取SkyDrive音乐外链方法20131003在文章底部更新,欢迎使用! 这已经是第三次写获取SkyDrive音乐外链mp3地址方法的文章了,因为第一次.第二次都失效了.三篇文章都有个共同点,都 ...
- iOS开发的调试技巧
关于本文: 1.模拟器的快捷键 2.覆盖安装注意事项 3.给模拟器相册增加照片 4.模拟器中程序的数据 5.安装旧版本的模拟器 6.模拟慢网速 7.异常断点与符号断点 1.模拟器的快捷键 常用的模拟器 ...
- etc/passwd 和 /etc/shadow 文件内容及其解释
/etc/passwd 和 /etc/shadow 文件内容及其解释 默认情况下,/etc/passwd 存储有关本地用户的信息 /etc/passwd 采用以下格式: 1)username ...
- MariaDB——日志文件
数据库各类日志 查询日志: 记录每一条sql语句,建议不开启,因为如果访问量过大,会占用相当大的资源,影响数据库的性能. vim /etc/my.cnf.d/server.cnf g ...
- pug
https://github.com/pugjs/pug pug模板使用https://www.cnblogs.com/gudi/p/8080736.html
- Mybatis入门(六)联查之一对多
上一章说了多对一,很多学生被一个老师教,这一章是一个老师教很多学生 目录基本没有变化只是改了配置文件: 2.配置文件: TeacherMapper接口类: package com.hdlf.dao; ...