poj 3692 Kindergarten
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 6956 | Accepted: 3436 |
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
- 翻译:小朋友手拉手做游戏,现在老师希望从小朋友当中挑出一个集合,集合中的小朋友全都认识,那么这个集合最大是多少。
思路:显然是个最大独立集问题,只是男女小朋友关系图的补图的最大独立集,其补图中两个人相互连线意味着相互不认识,从图中挑出来的最大独立集就是题设要求的。
AC代码:
- #define _CRT_SECURE_NO_DEPRECATE
- #include<iostream>
- #include<algorithm>
- #include<queue>
- #include<set>
- #include<vector>
- #include<cstring>
- #include<string>
- using namespace std;
- #define INF 0x3f3f3f3f
- const int N_MAX = ;
- int V;//点的个数
- vector<int>G[N_MAX];
- int match[N_MAX];
- bool used[N_MAX];
- void add_edge(int u, int v) {
- G[u].push_back(v);
- G[v].push_back(u);
- }
- bool dfs(int v) {
- used[v] = true;
- for (int i = ; i < G[v].size(); i++) {
- int u = G[v][i], w = match[u];
- if (w < || !used[w] && dfs(w)) {
- match[v] = u;
- match[u] = v;
- return true;
- }
- }
- return false;
- }
- int bipartite_matching() {
- int res = ;
- memset(match, -, sizeof(match));
- for (int v = ; v < V; v++) {
- if (match[v] < ) {
- memset(used, , sizeof(used));
- if (dfs(v))
- res++;
- }
- }
- return res;
- }
- bool vis[N_MAX][N_MAX];
- int g, B, M;
- int main() {
- int Case = ;
- while (scanf("%d%d%d",&g,&B,&M)&&g) {
- Case++;
- //0~g-1:girl
- //g~g+B-1:boy
- V = g + B;
- memset(vis,,sizeof(vis));
- for (int i = ; i < M; i++) {
- int a, b;
- scanf("%d%d",&a,&b);
- a--, b--;
- vis[a][g + b]=true;
- }
- for (int i=; i<g;i++) {
- for (int j = g; j < V;j++) {
- if (!vis[i][j]) {//建立原图的补图
- add_edge(i,j);
- }
- }
- }
- printf("Case %d: %d\n",Case,V-bipartite_matching());
- for (int i = ; i < V;i++) {
- G[i].clear();
- }
- }
- return ;
- }
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 (补图是二分图的最大团问题)
题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...
- POJ 3692 Kindergarten(二分图最大独立集)
题意: 有G个女孩,B个男孩.女孩彼此互相认识,男孩也彼此互相认识.有M对男孩和女孩是认识的.分别是(g1,b1),.....(gm,bm). 现在老师要在这G+B个小孩中挑出一些人,条件是这些人都互 ...
- POJ 3692:Kindergarten(最大的使命)
id=3692">Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4920 Ac ...
- POJ 3692:Kindergarten 求补图的最大点独立集 头一次接触这样的做法
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5884 Accepted: 2877 Desc ...
随机推荐
- OpenGL Frustum参数设置
opengl中使用Frustum来设置透视投影,函数原型: frustum(float left, float right, float buttom, float top, float near, ...
- mongo ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
解决方法 rm /var/lib/mongodb/mongod.lock
- HDOJ 4509 湫湫系列故事——减肥记II(2013腾讯编程马拉松) 并查集合并区间
发现这种合并区间的题目还可以这么玩 给你n段时间 然后问没被占用的时间是多少 题目所给的区间是右开的导致我wa 好多人5e5*1440的暴力跑出来的时间居然只是我的两倍 不懂.... 所以并查集并没有 ...
- Asp.Net Core 入门(五)—— 布局视图_Layout.cshtml
布局视图和我们在Asp.Net MVC一样,布局视图_Layout.cshtml使得所有视图保持一致的外观变得更加容易,因为我们只有一个要修改的布局视图文件,更改后将立即反映在整个应用程序的所有视图中 ...
- Asp.Net Core 入门(六)—— 路由
Asp.Net Core MVC的路由在Startup.cs文件中的Configure方法中进行配置,使其加入到Http请求管道中,如果不配置,那么我们所发送的请求无法得到象应. 那么该怎么配置Asp ...
- 初识 Hibernate
Hibernate 框架 1.1 什么是框架? 框架是一个提供了可重用的公共结构半成品. 2.1 关于Hibernate Hibernate是数据持久层的一个轻量级框架.数据持久层的框架有很多 ...
- shell脚本,一个字符一个字符输出。
[root@localhost wyb]# cat file abc def abc 789de f567 [root@localhost wyb]# cat fffile.sh #!/bin/bas ...
- shell脚本,计算1+3+5....100等于多少?
[root@localhost wyb]# cat unevenjia.sh #!/bin/bash #从1+++...100的结果 i= count=$1 $count` do sum=$(($su ...
- WebAssembly MDN简单使用
MDN 就是通过编译器编译完成c后生成的胶水代码 引入js 就能直接调用定义在c或者c++中的函数了 c代码如下: #include <stdio.h> #include <stdl ...
- Linux用户身份(命令详解与补正)
基于Red Hat Enterprise Linux 7.5 Linux中的root就是存在于所有类UNIX系统中的超级用户,持有最高管理权限,能添加/删除用户.开关机.关闭或开启硬件或者系统服务等, ...