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

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
题解:男生女生可能会相互吸引,就爱上了彼此,所以让你写一个程序,让找出他们不是相互喜欢的集合数目;
代码:
 #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(匈牙利)的更多相关文章

  1. POJ 1466 Girls and Boys (匈牙利算法 最大独立集)

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 10912   Accepted: 4887 D ...

  2. TZOJ 1321 Girls and Boys(匈牙利最大独立集)

    描述 the second year of the university somebody started a study on the romantic relations between the ...

  3. hdu1068 Girls and Boys 匈牙利算法(邻接表)

    #include <cstdio> #include <algorithm> #include <cstring> #include <vector> ...

  4. hdoj 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(匈牙利算法求最大独立集)

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

  6. 网络流(最大独立点集):POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...

  7. poj 1466 Girls and Boys 二分图的最大匹配

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...

  8. POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...

  9. Girls and Boys

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

随机推荐

  1. 简单的web三层架构系统【第五版】

    接上一版,今天差不多就是三层架构后台代码的完结了,这一版写完,接下来就是前台的制作了,前台不太熟悉,还在深入学习.过一段时间在写,今天先把后台代码写完. 三层架构包括DAL层, BLL层, UI层(也 ...

  2. 更改mysql 数据库名称

    //创建新数据库 CREATE DATABASE hbwebTemporary; //移植每个表 RENAME TABLE hbweb.aircraft_info TO hbwebTemporary. ...

  3. 浅谈Struts2(三)

    一.Struts2收集client的参数 核心思路: <form method="post" action="XXXX"> <input ty ...

  4. jquery+easy ui 实现表格列头筛选

    示例代码 1.筛选的下拉 <a href="javascript:void(0)" id="filterStatus" class="easyu ...

  5. 4.PHP 教程_PHP 变量

    PHP 变量 变量是用于存储信息的"容器": <?php $x = 5; $y = 6; $z = $x + $y; echo $z; ?> 与代数相似 x=5 y=6 ...

  6. Python学习之字符串函数

    下面是在看python核心编程中序列字符串中提到的一些函数,根据自己的学习理解总结了下,方便日后用到的时候查看.    1.string.capitalize() 把字符串的第一个字符大写 例子:   ...

  7. MVC-03 控制器(3)

    Controller负责处理浏览器来的所有要求,并决定响应什么属性给浏览器,以及协调Model与View之间的数据传递.在ASP.NET MVC中有好几种传递数据给视图的方式,例如从ASP.NET M ...

  8. Qt容器类的对象模型及应用(线性结构篇)(好多图,比较清楚)

    用Qt做过项目开发的人,肯定使用过诸如QList.QVector.QLinkList这样的模板容器类,它们虽然名字长的不同,但使用方法都大致相同, 因为其使用方法都大体相同,很多人可能随便拿一个容器类 ...

  9. php中 $$str 中 "$$" 的解释

    原文:php中 $$str 中 "$$" 的解释 这种写法称为可变变量有时候使用可变变量名是很方便的.就是说,一个变量的变量名可以动态的设置和使用.一个普通的变量通过声明来设置,例 ...

  10. C++那些库

    在C++中,库的地位是非常高的. 基础库 boost“准”标准库 boost库是经过千锤百炼,可移植提供源代码的C++库,作为标准库的后备.跨平台的.有一个大的C++社区支持 Boost中比较著名的库 ...