POJ 1466 Girls and Boys
Girls and Boys
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://poj.org/problem?id=1466
Description
In 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.
Input
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 (n <=500 ), for n subjects.
Output
For each given data set, the program should write to standard output a line containing the result.
Sample Input
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
2
HINT
要求找到一个点集合,让这个集合中并没有人互相喜欢
找相互喜欢的人的最大匹配,答案为总人数-匹配数/2
做的时候又忘了数据初始化,悲伤
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int mxn=;
int n;
vector<int>mp[mxn];
int vis[mxn];
int mc[mxn];
int x;
inline int read(){
int x=;
char ch=getchar();
while(ch<''||ch>'')ch=getchar();
while(ch>='' && ch<=''){ x=x*+ch-'';ch=getchar(); }
return x;
}
int dfs(int u){
for(int i=;i<mp[u].size();i++){
int v=mp[u][i];
if(!vis[v]){
vis[v]=;
if(mc[v]==- || dfs(mc[v])){
mc[v]=u;
return ;
}
}
}
return ;
}
int Maxmatch(){
int res=;
memset(mc,-,sizeof(mc));
int i;
for(i=;i<n;i++){
{
memset(vis,,sizeof(vis));
res+=dfs(i);
}
}
return res;
}
int main(){
while(scanf("%d",&n)!=EOF){
//read
for(int i=;i<=n;i++) mp[i].clear();
for(int L=;L<=n;L++){
int u,v;
u=read();
int i,j;
x=read();
for(i=;i<x;i++){
v=read();
mp[u].push_back(v);
}
}
//read finished
int ans=Maxmatch();
printf("%d\n",n-ans/);
}
return ;
}
POJ 1466 Girls and Boys的更多相关文章
- poj 1466 Girls and Boys(二分图的最大独立集)
http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submis ...
- 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: 5000MS Memory Limit: 10000K Total Submissions: 10912 Accepted: 4887 D ...
- 网络流(最大独立点集):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 (最大独立集)
链接:poj 1466 题意:有n个学生,每一个学生都和一些人有关系,如今要你找出最大的人数.使得这些人之间没关系 思路:求最大独立集,最大独立集=点数-最大匹配数 分析:建图时应该是一边是男生的点, ...
- POJ 1466 Girls and Boys(二分图匹配)
[题目链接] http://poj.org/problem?id=1466 [题目大意] 给出一些人和他们所喜欢的人,两个人相互喜欢就能配成一对, 问最后没有配对的人的最少数量 [题解] 求最少数量, ...
- POJ 1466 Girls and Boys (ZOJ 1137 )最大独立点集
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=137 http://poj.org/problem?id=1466 题目大意: ...
- POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题
有n个人, 其中有男生和女生,接着有n行,分别给出了每一个人暗恋的对象(不止暗恋一个) 现在要从这n个人中找出一个最大集合,满足这个集合中的任意2个人,都没有暗恋这种关系. 输出集合的元素个数. 刚开 ...
- poj 1466 Girls and Boys(二分匹配之最大独立集)
Description In the second year of the university somebody started a study on the romantic relations ...
随机推荐
- C#中treeview的问题,如何区分根节点和子节点以及根节点和根节点的兄弟节点?
根节点的Level属性为0,一级子节点Level属性为1,二级子节点Level属性为2,以此类推:同级节点可以用索引.名称.文本来区分.用索引区分根节点时,TreeView.Nodes[0]就是第一个 ...
- 转: 借助GitHub托管你的项目代码
转自:http://www.cnblogs.com/edisonchou/p/5990875.html 备注: 原贴关于github使用说明,非常详细易懂.建议看原帖. 借助GitHub托管你的项目代 ...
- memcached缓存知识简单梳理
memcached工作原理基本概念:slab,page,chunk.slab,是一个逻辑概念.它是在启动memcached实例的时候预处理好的,每个slab对应一个chunk size,也就是说不同s ...
- php安全配置记录
Php环境部署完成后,通常我们会进行一些安全设置.除了熟悉各种PHP漏洞外,还可以通过配置php.ini来加固PHP的运行环境.PHP官方也曾经多次修改php.ini的默认设置. 接下来,推荐php. ...
- WPF用ShowDialog()弹出窗体时控制该窗体的显示位置,并传值回父窗体
原文:http://blog.csdn.net/kiss0622/article/details/5852153 方法一: 1.父窗口代码 Window1.xaml.cs private void B ...
- Android应用开发中如何使用隐藏API(转)
一开始需要说明的是,Google之所以要将一些API隐藏(指加上@hide标记的public类.方法或常量)是有原因的.其中很大的原因就是Android系统本身还在不断的进化发展中.从1.0.1.1到 ...
- Linux ssh登录和软件安装详解
阿哲Style Linux第一天 ssh登录和软件安装详解 Linux学习第一天 操作环境: Ubuntu 16.04 Win10系统,使用putty_V0.63 本身学习Linux就是想在服务器 ...
- Linux 进程与线程一(创建-关闭线程)
进程是一个实体.每一个进程都有他自己的内存地址段(heap,stack等等) 进程是执行中的程序. 程序是一个没有生命的实体,只有处理器赋予程序生命时,它才能成为一个活动的实体. 进程是操作系统中最基 ...
- js 中常用的方法
1..call() 将.call()点之前的属性或方法,继承给括号中的对象. 2.(function(){xxx})() 解释:包围函数(function(){})的第一对括号向脚本返回未命名的函数, ...
- IBatis.Net学习笔记十三:在IBatis.Net中调用存储过程
其实调用方式比较简单,主要也就是两种类型的存储过程:1.更新类型的存储过程2.查询类型的存储过程下面就来看看具体的调用方式:1.更新类型的存储过程sp_InsertAccount: CREATE PR ...