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 ...
随机推荐
- Flash剪贴板功能
做JS的都知道,如果不考虑浏览器的兼容问题,其实,JS本身的window.clipboardData对象是可以做到复制内容到剪贴板的功能,但除了IE浏览器,FF和Chrome浏览器都不支持.现在为了浏 ...
- VS2013无法启动 IIS Express Web解决办法
不要勾选[覆盖应用程序根URL(U)],或让[覆盖应用程序根URL(U)]下面的输入框和上面的输入框的地址一样! 使用VS2013有一段时间了,因前期都是编写C/S程序,没有使用到B/S调试器.前几日 ...
- C# WinForm 中Console 重定向输出到ListBox控件中显示
{ VoidAction action = { lstBox.Items. ...
- Docker云Paas平台部署:Docker+Mesos+Marathon
针对“互联网+”时代的业务增长.变化速度及大规模计算的需求,廉价的.高可扩展的分布式x86集群已成为标准解决方案,如Google已经在几千万台服务器上部署分布式系统.Docker及其相关技术的出现和发 ...
- Google play billing(Google play 内支付)
准备工作 1. 通过Android SDK Manager下载extras中的Google Play services和Google Play Billing Library两个包. 2. 把下载的. ...
- WPF基础——Application
一.Application介绍 WPF中的Application对象用来进行一些全局的行为和操作,并且每个 Domain (应用程序域)中仅且只有一个 Application 实例存在.WPF App ...
- StaticFileMiddleware中间件如何处理针对文件请求
StaticFileMiddleware中间件如何处理针对文件请求 我们通过<以Web的形式发布静态文件>和<条件请求与区间请求>中的实例演示,以及上面针对条件请求和区间请求的 ...
- 检测到 LoaderLock:DLL"XXXX"正试图在OS加载程序锁内执行
解决方法: ctrl+D+E或alt+ctl+e或使用菜单调试——>异常——>异常窗口——>Managed Debugging Assistants——>去掉LoaderLoc ...
- 报这个错 unrecognized selector sent to instance
1.给一个对象赋空值: 2.调不存在的方法:3.数据类型不对.
- nodeJs--模块module.exports与实例化方法;
在nodejs中,提供了exports 和 require 两个对象,其中 exports 是模块公开的接口,require 用于从外部获取一个模块的接口,即所获取模块的 exports 对象.而在e ...