POJ 3692 Kindergarten(最大独立集)
2024-09-27 14:24:28
【题目链接】 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;
}
最新文章
- Linux和windows之间通过scp复制文件
- js删除数据的几种方法
- SOLR (全文检索)
- iOS开发之.pch文件初识
- 自定义对话框 提示:Unable to add window token null is not for an application
- iOS音频处理
- JavaWeb学习笔记--HttpServletRequest、HttpServletResponse对象常用方法
- 【京东账户】——Mysql/PHP/Ajax爬坑之用户登录
- Python 编程常见问题
- 无法使用 xxxx附加到应用程序
- lsof -i
- C# Asp.net中简单操作MongoDB数据库(二)
- 20165337岳源 第四次实验 Android开发
- SpringBoot使用WebFlux响应式编程操作数据库
- Spring-Boot之Redis基础
- DataFrame WordCount
- redmine和jenkins的ldap登录设置
- ECStore图片云端集群存储实践-又拍云存储
- ES monitoring
- 轻松学SQL Server数据库
热门文章
- yum命令Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
- 免费的dns服务器(更换dns服务器有时可以解决某些网站(如爱奇艺访问不了的问题))
- 从零开始学习MXnet(五)MXnet的黑科技之显存节省大法
- centos6上使用fpm打python2.7 rpm包并兼容python2.6
- CSS去掉 a 标签点击后出现的虚线框
- [洛谷P2127] 序列排序
- Shell之基本用法
- bzoj3779: 重组病毒 link-cut-tree
- HDU 2036 改革春风吹满地 (数学)
- es查询格式