*HDU 1068 二分图
Girls and Boys
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10929 Accepted Submission(s): 5100
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.
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
2
// 模板 匈牙利算法dfs 最大独立集=总结点数-最大匹配(有向图);最大独立集=总结点数-最大匹配/2(无向图),(图中任意两个顶点都不相连的顶点集合。)
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int mp[][],vis[],link[];
int Mu,Mv,n; //左集合点数,右集合点数,总点数
int dfs(int x) //找增广路。
{
for(int i=;i<Mv;i++)
{
if(!vis[i]&&mp[x][i])
{
vis[i]=;
if(link[i]==-||dfs(link[i]))
{
link[i]=x;
return ;
}
}
}
return ;
}
int Maxcon()
{
int ans=;
memset(link,-,sizeof(link));
for(int i=;i<Mu;i++)
{
memset(vis,,sizeof(vis));
if(dfs(i)) ans++;
}
return ans;
}
int main()
{
int a,b,c;
while(scanf("%d",&n)!=EOF)
{
memset(mp,,sizeof(mp));
for(int i=;i<n;i++)
{
scanf("%d: (%d)",&a,&c);
while(c--)
{
scanf("%d",&b);
mp[a][b]=mp[b][a]=;
}
}
Mu=Mv=n;
printf("%d\n",n-Maxcon()/);
}
return ;
}
*HDU 1068 二分图的更多相关文章
- Girls and Boys HDU - 1068 二分图匹配(匈牙利)+最大独立集证明
最大独立集证明参考:https://blog.csdn.net/qq_34564984/article/details/52778763 最大独立集证明: 上图,我们用两个红色的点覆盖了所有边.我们证 ...
- HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)
HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...
- hdu 5727 二分图+环排列
Necklace Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU 1068 Girls and Boys (二分图最大独立集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 有n个同学,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合 ...
- [HDU] 1068 Girls and Boys(二分图最大匹配)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1068 本题求二分图最大独立点集.因为最大独立点集=顶点数-最大匹配数.所以转化为求最大匹配.因为没有给 ...
- HDU 1068 Girls and Boys(模板——二分图最大匹配)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1068 Problem Description the second year of the univ ...
- hdu 1068 Girls and Boys 二分图的最大匹配
题目链接:pid=1068">http://acm.hdu.edu.cn/showproblem.php? pid=1068 #include <iostream> #in ...
- hdu - 1068 Girls and Boys (二分图最大独立集+拆点)
http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...
- (step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)
题目大意:第一行输入一个整数n,表示有n个节点.在接下来的n行中,每行的输入数据的格式是: 1: (2) 4 6 :表示编号为1的人认识2个人,他们分别是4.6: 求,最多能找到多少个人,他们互不认识 ...
随机推荐
- jvm七种垃圾收集器
JVM_七种垃圾收集器介绍 本文中的垃圾收集器研究背景为:HotSpot+JDK7 一.垃圾收集器概述 如上图所示,垃圾回收算法一共有7个,3个属于年轻代.三个属于年老代,G1属于横跨年轻代和年老 ...
- Python自动化之django视图
视图 1.获取用户请求数据 request.GET request.POST request.FILES PS: GET:获取数据 POST:提交数据 request其他方法详解:http://dja ...
- bzoj3674 可持久化并查集
我是萌萌的任意门 可持久化并查集的模板题-- 做法好像很多,可以标号法,可以森林法. 本来有O(mloglogn)的神算法(按秩合并+倍增),然而我这种鶸渣就只会写O(mlog2n)的民科算法--再加 ...
- Frame创建窗体实例
public class Test { public static void main(String[] args) { // TODO Auto-generated method stub Fram ...
- Python3实现简单的爬虫功能
python3简单实现一个爬去网站图片的小功能: 有时候想要下载自己喜欢的多个图片时,不需要一个个点击来下载,使用python脚本批量拉取,并保存到本地. 1. 首先找到自己要下载图片的url 2. ...
- Python:Pycharm下无法导入安装好的第三方模块?
Pycharm下无法导入安装好的第三方模块requests? 在cmd下使用pip安装好requests模块后,可以使用import requests,但在Pycharm IDE下无法导入,出现如下错 ...
- POJ 3155 Hard Life(最大密度子图)
裸题.输入一个无向图,输出最大密度子图(输出子图结点数和升序编号). 看了<最小割模型在信息学竞赛中的应用——胡伯涛>的一部分,感觉01分数规划问题又是个大坑.暂时还看不懂. 参考http ...
- 程序中使用ajax时,type为put,或者delete时在 IIS上没效果,发生HTTP Error 405.0 - Method Not Allowed
其实使用put delete 是在创建webapi中基本才会使用. WebDAV 是超文本传输协议 (HTTP) 的一组扩展,为 Internet 上计算机之间的编辑和文件管理提供了标准.利用这个协 ...
- CDN -- 集合
weui https://cdnjs.cloudflare.com/ajax/libs/weui/0.4.3/style/weui.min.css 百度静态资源库 http://cdn.code.ba ...
- 关于网络-get/post
关于网络: //英译 connection:连接 append:添加 resign:放弃 // 加载网页数据 步骤 [self.webView loadRequest:request]; NSURL ...