hdu1068 Girls and Boys 最大独立集
来源:互联网 发布:华为网络管理设备 编辑:程序博客网 时间:2024/05/20 11:49
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.
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.
题解:二分图最大独立集=节点数-最大匹配数。
求出来的最大匹配数要除2,因为题目没有给出哪些是男的哪些是女的,也就是说没有明显的二分图,所以将一个人拆成两个人进行最大匹配。由于一个拆成两个,所以最大匹配数应该是求出来的数除以2 。最后再用顶点数减就行了。
#include<cstdlib>#include<cstdio>#include<iostream>#include<cmath>#include<cstring>#include<algorithm>#define LL long long#define maxn 1001#define INF 2147483646using namespace std;int map[maxn][maxn];int link[maxn];int vit[maxn];int n;bool dfs(int u){ for(int i=0;i<n;i++) { if(map[u][i]&&!vit[i]) { vit[i]=1; if(link[i]==-1||dfs(link[i])) { link[i]=u; return true; } } } return false;}void solve(int &ans){ for(int i=0;i<n;i++) { memset(vit,0,sizeof(vit)); if(dfs(i)) ans++; }}int main(){ while(cin>>n) { int ans=0; memset(map,0,sizeof(map)); memset(link,-1,sizeof(link)); for(int i=0;i<n;i++) { int t,u; char a,b,c; cin>>t>>a>>b>>u>>c; for(int j=0;j<u;j++) { int x; cin>>x; map[i][x]=1; } } solve(ans); cout<<n-ans/2<<endl; }}
0 0
- hdu1068 Girls and Boys 最大独立集
- hdu1068 Girls and Boys最大独立集
- hdu1068 Girls and Boys 最大独立集
- hdu1068 Girls and Boys --- 最大独立集
- HDU1068 Girls and Boys 【最大独立集】
- HDU1068 Girls and Boys(最大独立集)
- hdu1068 Girls and Boys (二分图最大独立集)
- HDU1068 (最大独立集)Girls and Boys
- HDU1068-Girls and Boys(二分图_最大独立集)
- hdu1068 Girls and Boys,二分图最大独立集
- hdu1068 Girls and Boys(最大点独立集)
- hdu1068-Girls and Boys(最大独立集,匹配问题)
- 【HDU1068】Girls and Boys(最大独立集数,匈牙利算法)
- hdu1068解题报告--Girls and Boys--可以说是白话最大独立集学习总结
- HDU1068,POJ1466——Girls and Boys(二分图最大独立集)
- Girls and Boys----最大独立集(匹配)
- POJ1466-Girls and Boys(最大独立集)
- 最大独立集 poj1466 Girls and Boys
- 【Unity Shaders】Using Textures for Effects介绍
- Vasya and the Bus
- 一步步构建大型网站架构
- mybatis 获取Connection
- ae指定字段转成注记
- hdu1068 Girls and Boys 最大独立集
- 实用sql备忘(ORACLE)
- 资源帖子
- MFC对话框控件数据提取之DoDataExchange()
- fork()、vfork()、clone()和exec()
- JQuery文档注册事件
- 春运抢火车票攻略汇总(持续更新中)
- JAVA日期类
- ASLR (Address space layout randomization)技术和匿名页