题意:

有男生女生,男生都认识双方,女生都认识双方,给出一些男女关系,问最大拿多少个人,使得所有人都认识双方。

思路:

原图最大团=总结点数-[【补图(补图为二分图)】的最大独立集=最大完全子图的顶点数];

//#include<bits/stdc++.h>
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long LL; const int N=2e2+10; bool ma[N][N];
int n,m,e;
int cx[N],cy[N];
bool vis[N]; bool FindPath(int u)
{
for(int v=1;v<=m;v++)
{
if(ma[u][v]&&!vis[v])
{
vis[v]=true;
if(cy[v]==-1||FindPath(cy[v])){
cx[u]=v;
cy[v]=u;
return true;
}
}
}
return false;
} int MinPoint()
{
int res=0;
memset(cx,-1,sizeof(cx));
memset(cy,-1,sizeof(cy));
for(int i=1;i<=n;i++){
if(cx[i]==-1)
{
memset(vis,0,sizeof(vis));
res+=FindPath(i);
}
}
return res;
} int main()
{
int cas=1;
while(~scanf("%d%d%d",&n,&m,&e))
{
if(!n&&!m&&!e) break;
int u,v;
memset(ma,true,sizeof(ma));
while(e--)
{
scanf("%d%d",&u,&v);
ma[u][v]=false;
}
printf("Case %d: %d\n",cas++,n+m-MinPoint());
}
return 0;
}

POJ3692【二分匹配】的更多相关文章

  1. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  2. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  3. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

  4. Kingdom of Obsession---hdu5943(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...

  5. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  6. [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  7. [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)

    描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...

  8. nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...

  9. UVA5874 Social Holidaying 二分匹配

    二分匹配简单题,看懂题意,建图比较重要. #include<stdio.h> #include<string.h> #define maxn 1100 int map[maxn ...

  10. HDU 2236:无题II(二分搜索+二分匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2236 题意:中文题意. 思路:先找出最大和最小值,然后二分差值,对于每一个差值从下界开始枚举判断能不能二分匹配. ...

随机推荐

  1. nginx 安装和配置文件说明

    1. 安装依赖包 yum install gcc gcc+ yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel 2 ...

  2. ubuntu手机识别

    1.sudo gedit /etc/udev/rules.d/51-android.rules 2.将以下内容拷贝保存 SUBSYSTEM=="usb", ATTR{idVendo ...

  3. 01-bilibilidemo配置

    github-ijkplayer(bilibili)->cd 桌面位置 git clone https://github.com/Bilibili/ijkplayer.git ijkplayer ...

  4. Git Xcode配置

    本文转载至 http://www.cnblogs.com/imzzk/p/xcode_git.html 感谢作者分享 Git源代码管理工具的出现,使得我们开发人员对于源码的管理更加方便快捷.至于Git ...

  5. Android笔记之启动界面的设置

    默认情况下,启动界面是白屏 我们自定义一个启动界面如下,3秒钟后进入主界面并结束启动页 SplashActivity.java package com.bu_ish.myapp; import and ...

  6. zsh 的简单介绍

    什么是 zsh,要想解释好这个问题,那么得先说明什么是 shell.不负责任的解释说法就是 shell 就是一个壳.这个壳可不是蜗牛的壳,而是计算机的一个壳,当然也不是计算机的外壳啦,这个壳是相对于计 ...

  7. HDU1133 Buy the Ticket —— 卡特兰数

    题目链接:https://vjudge.net/problem/HDU-1133 Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Me ...

  8. Gradle build-info.xml not found for module app.Please make sure that you are using gradle plugin '2.0.0-alpha4' or higher.

    解决方法:去掉“Enable Instant run to host swap code/resource changes on deploy(default enabled)”的勾选项 Settin ...

  9. 浏览器端JS导出EXCEL——001

    <script src="https://rawgithub.com/eligrey/FileSaver.js/master/FileSaver.js" type=" ...

  10. hdu-4081 Qin Shi Huang's National Road System(最小生成树+bfs)

    题目链接: Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: ...