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 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 (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

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

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的更多相关文章

  1. poj 1466 Girls and Boys(二分图的最大独立集)

    http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submis ...

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

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

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

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

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

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

  5. poj 1466 Girls and Boys (最大独立集)

    链接:poj 1466 题意:有n个学生,每一个学生都和一些人有关系,如今要你找出最大的人数.使得这些人之间没关系 思路:求最大独立集,最大独立集=点数-最大匹配数 分析:建图时应该是一边是男生的点, ...

  6. POJ 1466 Girls and Boys(二分图匹配)

    [题目链接] http://poj.org/problem?id=1466 [题目大意] 给出一些人和他们所喜欢的人,两个人相互喜欢就能配成一对, 问最后没有配对的人的最少数量 [题解] 求最少数量, ...

  7. POJ 1466 Girls and Boys (ZOJ 1137 )最大独立点集

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=137 http://poj.org/problem?id=1466 题目大意: ...

  8. POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题

    有n个人, 其中有男生和女生,接着有n行,分别给出了每一个人暗恋的对象(不止暗恋一个) 现在要从这n个人中找出一个最大集合,满足这个集合中的任意2个人,都没有暗恋这种关系. 输出集合的元素个数. 刚开 ...

  9. poj 1466 Girls and Boys(二分匹配之最大独立集)

    Description In the second year of the university somebody started a study on the romantic relations ...

随机推荐

  1. php file_get_contents 绕过

    http://www.shiyanbar.com/ctf/1837 想到了经常出现的残留文件问题,于是尝试了一下:index.php~,index.php.bak, $flag='xxx';extra ...

  2. KVM虚拟机CPU说明

    废话不多说了,下面对kvm虚拟机的CPU说明做一梳理:NUMA技术介绍NUMA是一种解决多CPU共同工作的技术方案,我们先回顾下多CPU共同工作的技术架构历史.多CPU共同工作主要有三种架构,分别是S ...

  3. ztree插件(JQuery Tree)

    本次使用的ztree插件,基本上所有的需求都能满足,可谓功能强大. * [http://www.ztree.me/v3/api.php zTree v3.0 API 文档] * [http://www ...

  4. 【C#】IDispose接口的应用

    .net的GC机制有两个问题: 一.GC并不能释放所有资源,它更不能释放非托管资源. 二.GC也不是实时的,所有GC存在不确定性.所以需要使用析构函数,但是为了不重复GC,需要做一些处理. publi ...

  5. 添加web引用和添加服务引用有什么区别?

    添加web引用和添加服务引用有什么区别,Add Service References 和 Add Web References 有啥区别?参考 http://social.microsoft.com/ ...

  6. SQLServer 语句-创建索引

    语法:CREATE [索引类型] INDEX 索引名称ON 表名(列名)WITH FILLFACTOR = 填充因子值0~100GO /*实例*/USE 库名GOIF EXISTS (SELECT * ...

  7. java web 的标准目录结构(zz)

    http://blog.csdn.net/bluesnail216/article/details/7744607 --yourproject    --src       --java   运行的j ...

  8. LeetCode 笔记21 生成第k个排列

    题目是这样的: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all ...

  9. 信息安全系统设计基础exp_5

    北京电子科技学院(BESTI) 实     验    报     告 课程:信息安全系统设计基础 班级:1353 姓名:郑伟.吴子怡 学号:20135322.20135313 指导教师: 娄嘉鹏 实验 ...

  10. iOS 苹果自带地图定位Core Location

    Core Location是iOS SDK中一个提供设备位置的框架.可以使用三种技术来获取位置:GPS.蜂窝或WiFi.在这些技术中,GPS最为精准,如果有GPS硬件,Core Location将优先 ...