题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1068

本题求二分图最大独立点集。因为最大独立点集=顶点数-最大匹配数。所以转化为求最大匹配。因为没有给出男女,所以每个人都用了两遍,所以结果应该除以2。

 #include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdbool.h>
#include<time.h>
#include<stdlib.h>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define LL long long
#define INF 0x3f3f3f3f
#define A first
#define B second
#define PI 3.14159265358979323
const int N=+;
int n,m,f[N],g[N][N],link[N]; void init()
{
clr(f,);
clr(g,);
clr(link,-);
} bool find(int x)
{
for(int i=;i<n;i++) {
if(!f[i] && g[x][i]) {
f[i]=;
if(link[i]==- || find(link[i])) {
link[i]=x;
return true;
}
}
} return false;
} int hungary()
{
int ans=;
for(int i=;i<n;i++) {
clr(f,);
if(find(i)) ans++;
}
return ans;
} int main()
{
int u,v; while(~scanf("%d",&n)) {
init();
for(int i=;i<n;i++) {
scanf("%d: (%d)",&u,&m);
while(m--){
scanf("%d",&v);
g[u][v]=;
}
}
printf("%d\n",n-hungary()/);
} return ;
}

[HDU] 1068 Girls and Boys(二分图最大匹配)的更多相关文章

  1. HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. hdu 1068 Girls and Boys 二分图的最大匹配

    题目链接:pid=1068">http://acm.hdu.edu.cn/showproblem.php? pid=1068 #include <iostream> #in ...

  3. HDU 1068 Girls and Boys (二分图最大独立集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 有n个同学,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合 ...

  4. hdu - 1068 Girls and Boys (二分图最大独立集+拆点)

    http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...

  5. (step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)

    题目大意:第一行输入一个整数n,表示有n个节点.在接下来的n行中,每行的输入数据的格式是: 1: (2) 4 6 :表示编号为1的人认识2个人,他们分别是4.6: 求,最多能找到多少个人,他们互不认识 ...

  6. HDU 1068 Girls And Boys 二分图题解

    版权声明:本文作者靖心.靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...

  7. HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)

    HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...

  8. hdu 1068 Girls and Boys(匈牙利算法求最大独立集)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. HDU——1068 Girls and Boys

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. LeetCode_ Merge k Sorted Lists

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. / ...

  2. Android样式的编写格式

    <?xml version="1.0" encoding="utf-8"?> <resources> <style name=&q ...

  3. Oracle_Q&A_04

    2014-12-19作业 [JSU]LJDragon's Oracle course tasks In the first semester, junior year --1.在管理员权限下创建一个新 ...

  4. (ubuntu)在andorid andk工程中使用ccache加速编译速度

    环境 系统:Linux luogw-pc 3.5.0-36-generic #57~precise1-Ubuntu SMP Thu Jun 20 18:21:09 UTC 2013 x86_64 x8 ...

  5. [Git] Automatically running tests before commits with ghooks

    Wouldn't it be nice if everyone ran the tests before committing code? With ghooks, you can automatic ...

  6. [Redux] React Todo List Example (Adding a Todo)

    Learn how to create a React todo list application using the reducers we wrote before. /** * A reduce ...

  7. codeforce 437B The Child and Set

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  8. [小工具] Command-line CPU Killer(附源码及下载链接)

    博主有次在拆卸自己的笔记本电脑后,发现电脑如果静置时间长了有时会重启,但奇怪的是当我自己在电脑前工作的时候从来没有重启过.据此推测可能 CPU 完全空闲的时候风扇完全停转了,虽然 CPU 温度不高,但 ...

  9. mysql常用操作 mysql备份与恢复

    先登录mysql  ==>mysql -uroot -p  查看数据库的版本 select version(); 查看有哪些库 show datases; 查看当前处于哪个库 select da ...

  10. 10个最实用的Linux命令

    收集了一些对于Linux新手最基本但最有用的Linux命令.你完全可以键入这些命令来管理你的服务器.这些命令对于学习vps或服务器管理的新手最为简便.1.List命令 ls -a //列出所有文件 l ...