【题目链接】 http://poj.org/problem?id=3692

【题目大意】

  男生相互之间都认识,女生相互之间也都认识,
  一些男生和一些女生相互之间也认识,求找出最多的人参加派对,
  他们相互之间都认识

【题解】

  我们建认识图的反图,将相互之间不认识的连线,
  那么问题转化为求这个图的最大独立集,
  最大独立集答案为总点数减去最大匹配。

【代码】

#include <cstdio>
#include <cstring>
using namespace std;
const int MAXV=500;
int n,G[MAXV][MAXV],use[MAXV],match[MAXV];
int g,b,m,x,y,cas=0;
bool dfs(int x){
for(int i=1;i<=b;i++){
if(use[i]==0&&G[x][i]){
use[i]=1;
int j=match[i];
if(j==-1||dfs(j)){
match[i]=x;
return 1;
}
}
}return 0;
}
int bipartite_matching(){
int count=0;
memset(match,-1,sizeof(match));
for(int i=1;i<=g;i++){
for(int j=1;j<=b;j++)use[j]=0;
if(dfs(i))count++;
}return count;
}
void init(){
memset(G,1,sizeof(G));
for(int i=0;i<m;i++){
scanf("%d%d",&x,&y);
G[x][y]=0;
}
}
void solve(){
printf("%d\n",g+b-bipartite_matching());
}
int main(){
while(scanf("%d%d%d",&g,&b,&m),g||b||m){
printf("Case %d: ",++cas);
init();
solve();
}return 0;
}

POJ 3692 Kindergarten(最大独立集)的更多相关文章

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

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

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

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

  3. POJ 3692 Kindergarten(二分图最大独立集)

    题意: 有G个女孩,B个男孩.女孩彼此互相认识,男孩也彼此互相认识.有M对男孩和女孩是认识的.分别是(g1,b1),.....(gm,bm). 现在老师要在这G+B个小孩中挑出一些人,条件是这些人都互 ...

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

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

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

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

  6. poj 3692 Kindergarten

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6956   Accepted: 3436 Desc ...

  7. POJ 3692 Kindergarten (补图是二分图的最大团问题)

    题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...

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

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

  9. POJ 3692 最大独立集

    题意:有G个女生,B个男生,所有的女生都互相认识,所有的男生都互相认识,还有N对男女,他们互相认识. 问从中选出最多的人数,是的他们全部互相认识. 思路:这道题的构图很巧妙,对于他的补图构图,对于所有 ...

随机推荐

  1. MySQL DELAY_KEY_WRITE Option

    delay_key_write   This option applies only to MyISAM tables. It can have one of the following values ...

  2. Light OJ 1074:Extended Traffic(spfa判负环)

    Extended Traffic 题目链接:https://vjudge.net/problem/LightOJ-1074 Description: Dhaka city is getting cro ...

  3. Python代码规范

    一:背景 用于规范化ocp python开发,对于使用python开发的程序使用统一的风格,便于代码的维护 二:python风格规范 分号:不要在行尾加分号,也不要用分号将两条命令放在同一行 括号:宁 ...

  4. c++ STL(2)

    Vector: #include "stdafx.h" #include<iostream> #include<vector> #include<al ...

  5. ios 全方位修改工程名

    本文针对于彻底修改iOS工程名,不需要另外建工程,会整理的跟新工程完全一样 1. 选中旧工程名,改为新的 然后选择rename 2. 依次选择黄色文件夹,修改名字,千万不要在Xcode外修改!!! 修 ...

  6. 设置查看java的源程序

    1.点 “window”-> "Preferences" -> "Java" -> "Installed JRES" 2. ...

  7. MyBatis系列二 之 数据库列名于程序实体类中字段名称不一致

    MyBatis系列二  之   数据库列名于程序实体类中字段名称不一致 情景:当数据库中的列名与我们程序实体类中的字段名称不一致         使用ResultMap节点配置信息  在映射文件中  ...

  8. HDU 1162 Eddy's picture (最小生成树 普里姆 )

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  9. [转]树莓派gpio口控制

    0.前言     树莓派现在越来越火,网上树莓派的资料也越来越多.树莓派源自英国,国外嵌入式开源领域具有良好的分享精神,树莓派各种集成库也层出不穷,下面推荐几个. [[开发语言]——python [[ ...

  10. [Leetcode Week3]Evaluate Division

    Evaluate Division题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/evaluate-division/description/ Desc ...