HDU 1068 Girls and Boys(模板——二分图最大匹配)

时间:2022-09-17 22:17:18

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1068

Problem Description
the second year of the university somebody started a study on the romantic relations between the students. The relation “romantically involved” is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been “romantically involved”. The result of the program is the number of students in such a set.

The
input

contains several data sets in text format. Each data set
represents one set of subjects of the study, with the following
description:

the number of students
the description of each student, in the following format
student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
or
student_identifier:(0)

The student_identifier is an integer number between 0 and n-1, for n subjects.
For each given data set, the program should write to standard

output
a line containing the result.
 
Sample Input
7
0: (3) 4 5 6
1: (2) 4 6
2: (0)
3: (0)
4: (2) 0 1
5: (1) 0
6: (2) 0 1
3
0: (2) 1 2
1: (1) 0
2: (1) 0
 
Sample Output
5
2
解题思路:
处理数据,使用匈牙利算法即可。
AC代码:
#include<stdio.h>
#include<string.h>
const int N=;
int n,e[N][N],match[*N],bk[N];
int maxmatch();
int path(int u); int main()
{
int i,t,x,m;
while(scanf("%d",&n) != EOF)
{
memset(e,,sizeof(e));
for(i=;i<n;i++)
{
scanf("%d: (%d)",&x,&t);
while(t--)
{
scanf("%d",&m);
e[x][m]=;
}
} printf("%d\n",n-maxmatch());//最大点独立集数=顶点数-最大匹配数
}
return ;
}
int maxmatch()
{
int i;
int ans=;
memset(match,-,sizeof(match));
for(i=;i<n;i++)
{
if(match[i]==-)
{
memset(bk,,sizeof(bk));
ans += path(i);
}
}
return ans;
}
int path(int u)
{
int i;
for(i=;i<n;i++)
{
if(e[u][i] && !bk[i])
{
bk[i]=;
if(match[i]==- || path(match[i]))//或而不是且
{
match[i]=u;
match[u]=i;
return ;
}
}
}
return ;
}
//易错分析
//参见注释处
 

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

  1. HDU 1068 Girls and Boys&lpar;最大独立集合 &equals; 顶点数 - 最大匹配数&rpar;

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

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

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

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

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

  4. HDU——1068 Girls and Boys

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

  5. hdu 1068 Girls and Boys &lpar;二分匹配&rpar;

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

  6. hdu 1068 Girls and Boys &lpar;最大独立集&rpar;

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

  7. &lbrack;HDU&rsqb; 1068 Girls and Boys&lpar;二分图最大匹配&rpar;

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1068 本题求二分图最大独立点集.因为最大独立点集=顶点数-最大匹配数.所以转化为求最大匹配.因为没有给 ...

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

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

  9. HDU 1068 Girls and Boys &lpar;二分图最大独立集&rpar;

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

随机推荐

  1. (转)jQuery EasyUI Tree - TreeGrid动态加载子节点

    有时我们已经得到充分的分层树形网格(TreeGrid)的数据. 我们还想让树形网格(TreeGrid)按层次惰性加载节点. 首先,只加载顶层节点. 然后点击节点的展开图标来加载它的子节点. 本教程展示 ...

  2. php中将url中的参数含有&percnt;20进行转换或解码

    我的url: .......index.php?action=search&start=12&search=star wave&orderby=categories&s ...

  3. 基于Vue的小日历(支持按周切换)

      基于Vue的日历小功能,可根据实际开发情况按每年.每月.每周.进行切换 <template> <div class="date"> <!-- 年份 ...

  4. &lbrack;转&rsqb;树莓派&period;设置自动重连WiFi

    由于不可知的原因,有可能会导致树莓派失去连接,这时候需要重新连接WiFi. 自动重连的原理是,定期查看是否断网,如果断网了重启WiFi,参考的文章是这篇,第一步略有修改. 1.Python 代码 au ...

  5. Asp&period;net core 启动流程

  6. JavaScript 功能类 Url&period;js

    简书原文 这个类的主要目的是为了方便平时编码中的Url类型的数据操作 Github 全局名称 全局名称是由源码的最后一行代码确定的,默认为Url,如存在相同名称的对象会抛出异常: 可以通过 requi ...

  7. &lbrack;转&rsqb; web前端js构造无法销毁的类UUID识别码,识别浏览器设备唯一性

    用户行为统计在如今的前端生态中已是稀松寻常,如各种站长统计工具.识别用户访问客户端唯一性是必要的实现,对于web前端获取的设备信息,一般容易想到的是通过navigator.userAgent,但相同设 ...

  8. 极限树&lpar;extraTree&rpar;总结

    随机森林:是一个包含多个决策树的分类器, 并且其输出的类别是由个别树输出的类别的众数而定.随机森林对回归的结果在内部是取得平均但是并不是所有的回归都是取的平均,有些是取的和. 随机森林里的随机 极限树 ...

  9. 域控场景下windows安全日志的分析--审计认证行为和命令的历史记录

    https://www.cnblogs.com/KevinGeorge/p/8563458.html 一.域控windows安全日志基本操作 1.打开powershell或者cmd 1 #gpedit ...

  10. mysql的时区错误的解决办法

    十二月 02, 2018 9:16:19 下午 com.mchange.v2.resourcepool.BasicResourcePool 警告: Having failed to acquire a ...