有一个集合男和一个集合女,给出两集合间一些一一相应关系。问该两集合中的最大独立集的点数。

最大独立集=顶点总数-最大匹配数

此题中。若(a,b)有关。则(b,a)有关。每个关系算了两次,相当于二分图的两边集合没有分男女。两边都是总人数。

所以此题中答案应该是 顶点总数-最大匹配数/2

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
const int maxn=510;
using namespace std; int mx[maxn],my[maxn],vis[maxn],e[maxn][maxn],n; int path(int i)
{
int j;
for(j=0;j<n;j++)
{
if(e[i][j]&&!vis[j])
{
vis[j]=1;
if(my[j]==-1||path(my[j]))
{
my[j]=i;
mx[i]=j;
return 1;
}
}
}
return 0;
} int hungry()
{
int res=0;
memset(mx,-1,sizeof mx);
memset(my,-1,sizeof my);
for(int i=0;i<n;i++)
{
if(mx[i]==-1)
{
memset(vis,0,sizeof vis);
res+=path(i);
}
}
return res;
} int main()
{
int a,b,m,i;
while(~scanf("%d",&n))
{
memset(e,0,sizeof e);
for(i=0;i<n;i++)
{
scanf("%d: (%d)",&a,&m);
while(m--)
{
scanf("%d",&b);
e[a][b]=1;
}
}
printf("%d\n",n-hungry()/2);
}
return 0;
}

hdu1068 Girls and Boys --- 最大独立集的更多相关文章

  1. hdu 1068 Girls and Boys (最大独立集)

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

  2. hdu1068 Girls and Boys

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1068 二分图的最大独立集数=节点数(n)— 最大匹配数(m) 另外需要注意的是: 本题求出的最大匹配数是实 ...

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

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

  4. hdu1068 Girls and Boys 二分匹配

    题目链接: 二分匹配的应用 求最大独立集 最大独立集等于=顶点数-匹配数 本体中由于男孩和女孩的学号是不分开的,所以匹配数应是求得的匹配数/2 代码: #include<iostream> ...

  5. hdu1068 Girls and Boys 匈牙利算法(邻接表)

    #include <cstdio> #include <algorithm> #include <cstring> #include <vector> ...

  6. hdu1068 Girls and Boys 基础匈牙利

    #include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> ...

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

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

  8. poj 1466 Girls and Boys(二分图的最大独立集)

    http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submis ...

  9. hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】

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

随机推荐

  1. hbuilder中的 http://www.w3.org/TR/html4/loose.dtd

    <!-- This is the HTML 4.01 Transitional DTD, which includes presentation attributes and elements ...

  2. jsp里post和get的乱码解决问题

    6.乱码问题01:<%reques.setCharacterEncoding("utf-8");%> 02:get请求乱码 001.:String 编码之后的字符串 = ...

  3. 回收maven私仓过期垃圾

    login->scheduled tasks->add

  4. 如何用java生成随机验证码

     1.VerifyCode 类:   1 package com.HRuinger.enity;                          ImageIO.write(image, " ...

  5. svg文件使用highmap显示

    svg文件使用highmap显示 highmap,ammap都是比较好的第三方插件用来显示svg图片:     ammap导航可能更美观点(这个highmap后面可能也会赶上),     highma ...

  6. C# Winform 获得下拉框 选中的值

    string PrintName = cmbPrinter.SelectedIndex.ToString(); PrintName = cmbPrinter.SelectedItem.ToString ...

  7. Sybase_ASA 字符串拼接

    列转行并拼接字符串,使用LIST函数 SELECT LIST(T.NAME,',') FROM TAB_DEMO T;

  8. node.js(API解读) - process (http://snoopyxdy.blog.163.com/blog/static/60117440201192841649337/)

    node.js(API解读) - process 2011-10-28 17:05:34|  分类: node |  标签:nodejs  nodejsprocess  node.jsprocess  ...

  9. react 父组件调用子组件方法

    import React from 'react'import '../page1/header.css'import { Table } from 'antd'import Child from ' ...

  10. SqlServer IsNull 与 NullIf

    ISNULL(check_expression, replacement_value) check_expression 与 replacement_value 数据类型必须一致,如果 check_e ...