【题目链接】 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;
}

最新文章

  1. Linux和windows之间通过scp复制文件
  2. js删除数据的几种方法
  3. SOLR (全文检索)
  4. iOS开发之.pch文件初识
  5. 自定义对话框 提示:Unable to add window token null is not for an application
  6. iOS音频处理
  7. JavaWeb学习笔记--HttpServletRequest、HttpServletResponse对象常用方法
  8. 【京东账户】——Mysql/PHP/Ajax爬坑之用户登录
  9. Python 编程常见问题
  10. 无法使用 xxxx附加到应用程序
  11. lsof -i
  12. C# Asp.net中简单操作MongoDB数据库(二)
  13. 20165337岳源 第四次实验 Android开发
  14. SpringBoot使用WebFlux响应式编程操作数据库
  15. Spring-Boot之Redis基础
  16. DataFrame WordCount
  17. redmine和jenkins的ldap登录设置
  18. ECStore图片云端集群存储实践-又拍云存储
  19. ES monitoring
  20. 轻松学SQL Server数据库

热门文章

  1. yum命令Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
  2. 免费的dns服务器(更换dns服务器有时可以解决某些网站(如爱奇艺访问不了的问题))
  3. 从零开始学习MXnet(五)MXnet的黑科技之显存节省大法
  4. centos6上使用fpm打python2.7 rpm包并兼容python2.6
  5. CSS去掉 a 标签点击后出现的虚线框
  6. [洛谷P2127] 序列排序
  7. Shell之基本用法
  8. bzoj3779: 重组病毒 link-cut-tree
  9. HDU 2036 改革春风吹满地 (数学)
  10. es查询格式