前边和后边性别不同!!!不然NP了

Girls and Boys

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
 
Source

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<string>
#include<memory.h>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
int Map[][];
int used[],linke[];
int s,t,n;
int _S(){
char c=getchar();
while(c>''||c<'') c=getchar();
int num=;
while(c<=''&&c>='') {
num=num*+c-'';
c=getchar();
}
return num;
}
bool _find(int v)
{
for(int i=;i<=n;i++){
if(Map[v][i]&&!used[i])
{
used[i]=;
if((linke[i]==-)||_find(linke[i])){
linke[i]=v;
return true;
}
}
}
return false;
}
int main()
{
int m,i,j,ans=,tmp;
while(~scanf("%d",&n)){
ans=;
memset(linke,-,sizeof(linke));
memset(Map,,sizeof(Map));
for(int d=;d<=n;d++){
s=_S();
tmp=_S();
for(i=;i<=tmp;i++){
t=_S();
Map[s+][t+]=;
}
} for(i=;i<=n;i++){
memset(used,,sizeof(used));
if(_find(i)) ans++;
} cout<<n-ans/<<endl;
}
return ;
}

 

HDU1068 二分匹配 独立集的更多相关文章

  1. hdu1068 Girls and Boys 二分匹配

    题目链接: 二分匹配的应用 求最大独立集 最大独立集等于=顶点数-匹配数 本体中由于男孩和女孩的学号是不分开的,所以匹配数应是求得的匹配数/2 代码: #include<iostream> ...

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

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

  3. HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)

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

  4. kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树

    二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...

  5. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  6. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  7. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

  8. Kingdom of Obsession---hdu5943(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...

  9. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

随机推荐

  1. memcached常用命令

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt104 一.Memcache面向对象的常用接口包括:Memcache::con ...

  2. ActiveMQ持久化消息的三种方式

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt362 本文只介绍三种方式,分别是持久化为文件,MYSql,Oracle.下面 ...

  3. cocos2dx lua中异步加载网络图片,可用于显示微信头像

    最近在做一个棋牌项目,脚本语言用的lua,登录需要使用微信登录,用户头像用微信账户的头像,微信接口返回的头像是一个url,那么遇到的一个问题就是如何在lua中异步加载这个头像,先在引擎源码里找了下可能 ...

  4. 团队作业4——第一次项目冲刺 tHiRd DaY

    项目冲刺--Triple Kill 小编又来了,好困呐,上了一天的课还要写博客,为什么写博客的一直是我呢..一点乐子都没有*-* 但是我还是得写啊[我也很无奈啊],那就让我给大家找点乐子吧 天霸动霸. ...

  5. 【Alpha】——Fifth Scrum Meeting

    一.今日站立式会议照片 二.每个人的工作 成员 昨天已完成的工作 今天计划完成的工作 李永豪 测试统计功能 对统计出现的问题进一步完善 郑靖涛 着手编写报表设计 继续报表设计 杨海亮 协助编写统计功能 ...

  6. 201521123059 《Java程序设计》第二周学习总结

    1.本周总结 本周老师讲了和自己掌握了以下内容: (1).三元条件运算符 表达式1?表达式2:表达式3: (2). 字符串String类 String的不可变优点:编译器可以让字符串共享,效率高.但是 ...

  7. 陈敏-第一周Java课程总结

    一.本周学习总结 1.感受到JAVA的神奇魅力,以及其跨平台的优势 2.第一次接触感觉还是有很多不懂. 3.了解了JDK 二.书面作业 (一)为什么java程序可以跨平台运行?执行java程序的步骤是 ...

  8. 201521123007《Java程序设计》第11周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1. 互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) ...

  9. 201521123071 《JAVA程序设计》第九周学习总结

    第九周-异常 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 此处仅部分知识点归纳 2. 书面作业 1. 常用异常,题目5-1 1.1 截图你的提交结果(出现学号) ...

  10. 201521123052《Java程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己 ...