传送门:http://poj.org/problem?id=3692

Language:
Kindergarten
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 6831 Accepted: 3374
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
Source

2008 Asia Hefei Regional Contest Online by USTC

【解析】

题意:女孩们都互相认识,男孩们也都互相认识。有些男孩女孩互相认识,选出人数最多的互相认识的团体。

解法:求二分图的最大独立集。

如果我们选出的这些人两两互相认识,说明在一个图中这些点两两之间有连线,我们怎样找到这样一个图呢。

我们利用二分图的性质,将不认识的人连线。求最大独立集。最大独立集就是这个集合中的所有点两两之间没有连线。

没有连线就是互相认识。

最大独立集=所有的顶点个数-最大匹配。

【code】

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 200+10
int map[N][N],match[N];
bool vis[N];
int x,y,g,b,m,cnt,tim;
bool path(int x)
{
for(int i=;i<=b;i++)
{
if(!vis[i]&&!map[x][i])
{
vis[i]=;
if(!match[i]||path(match[i]))
{
match[i]=x;
return true;
}
}
}
return false;
}
int main()
{
while(scanf("%d%d%d",&g,&b,&m)&&g&&b&&m)
{
cnt=;//*注意清0
tim++;
memset(match,,sizeof(match));
memset(map,,sizeof(map));
for(int i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
map[x][y]=;
}
for(int i=;i<=g;i++)
{
memset(vis,,sizeof(vis));
if(path(i))
cnt++;
}
printf("Case %d: %d\n",tim,g+b-cnt);
}
return ;
}

Kindergarten的更多相关文章

  1. poj 3692 Kindergarten (最大独立集)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4903   Accepted: 2387 Desc ...

  2. codeforces 484D D. Kindergarten(dp)

    题目链接: D. Kindergarten time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #276 (Div. 1) D. Kindergarten dp

    D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...

  4. POJ3692 Kindergarten 【最大独立集】

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5317   Accepted: 2589 Desc ...

  5. poj 3692 Kindergarten (最大独立集之逆匹配)

    Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and al ...

  6. POJ 3692 Kindergarten (二分图 最大团)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5660   Accepted: 2756 Desc ...

  7. POJ 3692:Kindergarten(最大的使命)

    id=3692">Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4920   Ac ...

  8. Kindergarten Counting Game - UVa494

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva494.html 题目描述  Kin ...

  9. POJ3692 Kindergarten

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6882   Accepted: 3402 Desc ...

  10. POJ 3692 Kindergarten(最大团问题)

    题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girl ...

随机推荐

  1. StarUML破解教程

    StarUML破解教程 StarUML官方下载地址:http://staruml.io/download StarUML是一个非常好用的画UML图的工具,但是它是收费软件,以下是破解方法: 1.使用E ...

  2. C语言合并两个集合(L,L1) 将L1中不在L中的元素插入到L线性表中

    void main(){ Sqlist L,L1; InitList(&L); InitList(&L1); ListInsert(&L, 1, 2); ListInsert( ...

  3. [Matlab绘图][三维图形][三维曲线基本函数+三维曲面+其他三维图形]

    1.绘制三维图形的基本函数 最基本的三维绘图函数为plot3: plot3与plot用法十分相似,调用格式: plot(x1,y1,z1,选项1,x2,y2,z2,选项2,...,xn,yn,zn,选 ...

  4. SAP内表转XML文件

    今天有个兄弟问如何实现以XML的方式输出内表的内容,这个问题我以前好像没有写过.倒不是不会写,而是写的方法太多了,有极其简单的,也有很复杂的,而且网上资料也很多. 找到以前写的一个程序,稍微修改了一下 ...

  5. python 统计单词出现次数

    #use python3.6 import re from collections import Counter FILESOURCE = './abc.txt' def getMostCommonW ...

  6. linux下查找最耗iowait的进程

    抓哪个进程干坏事前要先停掉syslogservice syslog stop 打开block dump:echo 1 > /proc/sys/vm/block_dump 统计:dmesg | e ...

  7. 目标检测--之RCNN

    目标检测--之RCNN 前言,最近接触到的一个项目要用到目标检测,还有我的科研方向caption,都用到这个,最近电脑在windows下下载数据集,估计要一两天,也不能切换到ubuntu下撸代码~.所 ...

  8. 基于事件驱动的前端通信框架(封装socket.io)

    socket.io的使用可以很轻松的实现websockets,兼容所有浏览器,提供实时的用户体验,并且为程序员提供客户端与服务端一致的编程体验.但是在使用socket.io的过程中,由于业务需求需要同 ...

  9. C#Winform之等待窗体

    窗体主要代码: ? 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 ...

  10. 【leetcode刷题笔记】Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. For example, ...