Girls and Boys

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10132    Accepted Submission(s):
4660

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
 
复习了一下匈牙利算法。
之前用以为是并查集,最后发现不对,看题解说是二分匹配,但也没看出为什么是二分匹配。
然后看到了重点,也是今天图论课上学的αº+βº=n(点覆盖数+点独立数=顶点数,又有点覆盖数=二分最大匹配)
最大匹配,即图中最大边独立集。点覆盖数,即用最少的点覆盖所有的边。二分图的最大匹配数等于最小覆盖数,即求最少的点使得每条边都至少和其中的一个点相关联,很显然直接取最大匹配的一端节点即可。
匈牙利算法还需熟悉。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std; int map[][],t;
int link[],vis[]; int dfs(int x)
{
for(int i=; i<t; i++)
if(map[x][i]==)
if(vis[i]==)
{
vis[i]=;
if(link[i]==-||dfs(link[i]))
{
link[i]=x;
return ;
}
}
return ;
} int solve()
{
int ans=;
memset(link,-,sizeof(link));
for(int i=; i<t; i++)
{
memset(vis,,sizeof(vis));
if(dfs(i))
ans++;
}
return ans;
}
int main()
{
while(scanf("%d",&t)!=EOF)
{
memset(map,,sizeof(map));
for(int i=; i<t; i++)
{
int n,n1,num;
scanf("%d: (%d)",&n1,&n);
for(int j=; j<n; j++)
{
scanf("%d",&num);
map[i][num]=;
}
}
int ans=solve();
//cout<<ans<<endl;
printf("%d\n",t-ans/);
}
return ;
}

HDU_1068_Girls and Boys_二分图匹配的更多相关文章

  1. UVA 12549 - 二分图匹配

    题意:给定一个Y行X列的网格,网格种有重要位置和障碍物.要求用最少的机器人看守所有重要的位置,每个机器人放在一个格子里,面朝上下左右四个方向之一发出激光直到射到障碍物为止,沿途都是看守范围.机器人不会 ...

  2. POJ 1274 裸二分图匹配

    题意:每头奶牛都只愿意在她们喜欢的那些牛栏中产奶,告诉每头奶牛愿意产奶的牛棚编号,求出最多能分配到的牛栏的数量. 分析:直接二分图匹配: #include<stdio.h> #includ ...

  3. BZOJ1433 ZJOI2009 假期的宿舍 二分图匹配

    1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2375  Solved: 1005[Submit][Sta ...

  4. HDU1281-棋盘游戏-二分图匹配

    先跑一个二分图匹配,然后一一删去匹配上的边,看能不能达到最大匹配数,不能这条边就是重要边 /*----------------------------------------------------- ...

  5. HDU 1083 网络流之二分图匹配

    http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...

  6. hdu 5727 Necklace dfs+二分图匹配

    Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...

  7. BZOJ 1059 & 二分图匹配

    题意: 判断一个黑白染色的棋盘能否通过交换行或列使对角线上都是黑色. SOL: 真是有点醉...这种问题要么很神要么很水...第一眼感觉很水但就是不造怎么做...想了10分钟怎么感觉就是判断个数够不够 ...

  8. 【POJ 3020】Antenna Placement(二分图匹配)

    相当于用1*2的板覆盖给定的h*w的格子里的点,求最少的板.可以把格子相邻的分成两个集合,如下图,0为一个集合,1的为一个,也就是(行数+列数)为奇数的是一个集合,为偶数的为另一个集合.1010101 ...

  9. BZOJ-1143&&BZOJ-2718 祭祀river&&毕业旅行 最长反链(Floyed传递闭包+二分图匹配)

    蛋蛋安利的双倍经验题 1143: [CTSC2008]祭祀river Time Limit: 10 Sec Memory Limit: 162 MB Submit: 1901 Solved: 951 ...

随机推荐

  1. RAC fail over 测试

    oracle rac 11gr2中提供了多种 failover方式,这里只测试 server side TAF. 也就是说在server端配置的failover.这种配置方式的好处就是,如果有什么改动 ...

  2. open redis port for remote connections

    edit /etc/redis.conf Add below line after bind 127.0.0.1, then try redis-cli -h xxx.xxx.xxx.xxx ping ...

  3. 去除ckeditor上传图片预览中的英文字母

    去除ckeditor上传图片预览中的英文字母 CKEDITOR.replace('text', { filebrowserImageUploadUrl : 'upload_img.do', langu ...

  4. Hibernate——三种状态的理解

    在Hibernate中有三种状态,对这三种状态的深入的理解,能够更好的理解Hibernate的执行机制. 在整个Hibernate中这三种状态是能够进行转换的. 1.Transient Object( ...

  5. Unity编程笔录--ulua+PureMVC框架简单热更新使用

    ulua+PureMVC框架简单热更新使用 前言: 1:作者官网论坛 首先介绍的是这个框架是一位大牛  骏擎[CP]  jarjin   写的,据说原本是"非常多人不知道怎么使用Ulua,所 ...

  6. C++链表冒泡,归并,插入排序(纯指针)

    #include <iostream> using namespace std; //别问我为什么要写链表的冒泡排序. struct Node { int data; Node *next ...

  7. SoapUI在Jenkins中的配置

    Jenkins Label: windows_ws_test   已有Jenkins环境变量 %READYAPI_PRO_HOME%  - <D:\Program Files\SmartBear ...

  8. C# winform通过按钮上移下移 解决了datasource绑定问题

    事件代码: private void btn_frmDicType_MoveUp_Click(object sender, EventArgs e) { int lstLength = this.ls ...

  9. 硬盘-RAID 5组建

    没发正文之前本人先声明一下----本文是转载 这篇文章简直是太精彩了,呵呵 ,实在是忍不住了,一定要贴出来,让大家分享! 原作者:唐华 责任编辑:xiexiaojin 我们生活在一个历史记录在硬盘上的 ...

  10. POJ2985 The k-th Largest Group treap

    POJ2985 比较简单的平衡树题目 树内不要添加容量为1的节点 否则会超时. #include<iostream> #include<cstdio> #include< ...