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. Jenkins遇到问题一:jenkins配置权限不对导致无法登陆或者空白页面解决办法

    找到.jenkins/config.xml文件:替换为:1.<authorizationStrategy class="hudson.security.AuthorizationStr ...

  2. SQL Server 2005 安装图解教程(Windows)

    因工作需要,好久未安装SQL Server2005,今天安装了一下,特此写下安装步骤留下笔记. 安装前准备: 先安装IIS,再安装SQL Server2005 一.安装 点击安装,如下图: 选择操作系 ...

  3. 常用的adb命令

    在平时的工作中,会经常用到adb命令,在这里稍微整理了一下. 一.概要 1.什么是adb? adb全称为Android Debug Bridge,就是起到调试桥的作用.顾名思义,adb就是一个debu ...

  4. localStorage实现购物车数量单价和总价实时同步(二)

    利用localStorage实时显示购物车小计和总价页面显示: 和昨天的原理相同,本地存储同时实时循环计算总价之和,注意循环时候的先清空再计算 Success is getting what you ...

  5. [QoS]cisco3560限速配置案例-收集于网工泡泡

    网络中常用到这些:CISCO和H3C-MAC过滤+端口限速+端口镜像+端口隔离 不同的方式不同的思想:嘎嘎 其他各个厂商的限速链接:http://pan.baidu.com/s/1hrIMoSG 密码 ...

  6. 求时间差的sql语句。 比如如下数据

    msisdn createtime closetime138 2011-5-17 15:30:00:000 2011-5-17 15:30:00:530138 2011-5-17 15:40:00:0 ...

  7. 实践2.4 ELF文件格式分析

    实践2.4 ELF文件格式分析 1.ELF文件头 查看/usr/include/elf.h文件: #define EI_NIDENT (16) typedef struct { unsigned ch ...

  8. Operators一句话介绍(RxJava版)

    Cold Observables 在第一个subscriber订阅后才执行事件发送的Observables,默认普通Observables都是这个类型 Cold Observables对于每个订阅的s ...

  9. 怎样写 OpenStack Neutron 的 Plugin (一)

    鉴于不知道Neutron的人也不会看这篇文章,而知道的人也不用我再啰嗦Neutron是什么东西,我决定跳过Neutron简介,直接爆料. 首先要介绍一下我的开发环境.我没有使用DevStack,而是直 ...

  10. protobuf 文件级别优化

    package IM.BaseDefine;option java_package = "com.mogujie.tt.protobuf";option optimize_for ...