Girls and Boys(匈牙利)
Girls and Boys
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9245 Accepted Submission(s): 4240
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
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=;
vector<int>vec[MAXN];
int usd[MAXN],vis[MAXN];
bool dfs(int x){
for(int i=;i<vec[x].size();i++){
int v=vec[x][i];
if(!vis[v]){
vis[v]=;
if(usd[v]==-||dfs(usd[v])){
usd[v]=x;return true;
}
}
}
return false;
}
int main(){
int N,a,t;
while(~scanf("%d",&N)){
for(int i=;i<MAXN;i++)vec[i].clear();
for(int i=;i<N;i++){
scanf("%*d: (%d)",&t);
// printf("t=%d\n",t);
while(t--){
scanf("%d",&a);
vec[i].push_back(a);
}
}mem(usd,-);mem(vis,);
int ans=;
for(int i=;i<N;i++){
mem(vis,);
if(dfs(i))ans++;
}
printf("%d\n",N-ans/);
}
return ;
}
Girls and Boys(匈牙利)的更多相关文章
- POJ 1466 Girls and Boys (匈牙利算法 最大独立集)
Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 10912 Accepted: 4887 D ...
- TZOJ 1321 Girls and Boys(匈牙利最大独立集)
描述 the second year of the university somebody started a study on the romantic relations between the ...
- hdu1068 Girls and Boys 匈牙利算法(邻接表)
#include <cstdio> #include <algorithm> #include <cstring> #include <vector> ...
- hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1068 Girls and Boys(匈牙利算法求最大独立集)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 网络流(最大独立点集):POJ 1466 Girls and Boys
Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...
- poj 1466 Girls and Boys 二分图的最大匹配
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- POJ 1466 Girls and Boys
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- Girls and Boys
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- git 使用笔记(三)-分支的使用
简单介绍 之前说过,每次修改之后,Git 并不是保存这些修改之后的差异变化,实际上就像一个照相机一样,将修改后的文件拍下作为文件快照,记录在一个微型的文件系统中.在 Git 中提交时,会保存一个提交对 ...
- 关于对象和this、new
//创建一个猫类 function Cat(name,color,eyeColor){ //上面处Cat首字母大写表示创建一个‘类别’叫Cat类.假如首字母小写cat则是创建一个cat的函数: thi ...
- mvc模式jsp+servel+dbutils oracle基本增删改查demo
mvc模式jsp+servel+dbutils oracle基本增删改查demo 下载地址
- linux怎样修改用户权限
ls -l 查看目录下的文件详细信息 ll 同上 whoami 功能说明:先似乎用户名称. 语 法:whoami [--help][--version] 补充说明:显示自身的用户名称,本指令相当于执 ...
- Android 开发笔记 “java.util.Calendar.compareTo()”
java.util.Calendar.compareTo() 方法比较Calendar对象和anotherCalendar对象之间的时间值(毫秒偏移量). 声明 以下是java.util.Calen ...
- SqlServer2012导入Oracle详细案例
第一次使用SqlServer2012,界面和VS2012风格一致了,Great! 进入正题,这篇博文主要写一下自己亲测的一个案例,使用SqlServer2012的“导入和导出数据”功能向Oracle1 ...
- Installing on CentOS/RHEL / KB forum / Ajenti
Installing on CentOS/RHEL / KB forum / Ajenti Ajenti → KB → Installation Is it?: Inappropriate Spam ...
- http://blog.csdn.net/baimafujinji/article/details/10931621
书接上文,本文章是该系列的第二篇,按照总纲中给出的框架,本节介绍三个中值定理,包括它们的证明及几何意义.这三个中值定理是高等数学中非常基础的部分,如果读者对于高数的内容已经非常了解,大可跳过此部分.当 ...
- 简单的REST的框架实现
源代码下载地址:http://download.csdn.net/source/1662193 一. 认识REST REST软件架构是由Roy Thomas Fielding博士在2000年首次提出的 ...
- AS3 Post 参数和ByteArray的方法及服务器端接收
as端: (form表单形式)req.method = URLRequestMethod.POST; var reqHeader:URLRequestHeader = new URLRequestHe ...