The Perfect Stall
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 17768   Accepted: 8104

Description

Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering problems, all the stalls in the new barn are different. For the first week, Farmer John randomly assigned cows to stalls, but it quickly became clear that any given cow was only willing to produce milk in certain stalls. For the last week, Farmer John has been collecting data on which cows are willing to produce milk in which stalls. A stall may be only assigned to one cow, and, of course, a cow may be only assigned to one stall. 
Given the preferences of the cows, compute the maximum number of milk-producing assignments of cows to stalls that is possible. 

Input

The input includes several cases. For each case, the first line contains two integers, N (0 <= N <= 200) and M (0 <= M <= 200). N is the number of cows that Farmer John has and M is the number of stalls in the new barn. Each of the following N lines corresponds to a single cow. The first integer (Si) on the line is the number of stalls that the cow is willing to produce milk in (0 <= Si <= M). The subsequent Si integers on that line are the stalls in which that cow is willing to produce milk. The stall numbers will be integers in the range (1..M), and no stall will be listed twice for a given cow.

Output

For each case, output a single line with a single integer, the maximum number of milk-producing stall assignments that can be made.

Sample Input

5 5
2 2 5
3 2 3 4
2 1 5
3 1 2 5
1 2

Sample Output

4

Source

模板题:

 //168K    16MS    C++    960B    2014-06-03 12:15:26
#include<iostream>
#include<vector>
#define N 205
using namespace std;
vector<int>V[N];
int vis[N];
int match[N];
int n,m;
int dfs(int u)
{
for(int i=;i<V[u].size();i++){
int v=V[u][i];
if(!vis[v]){
vis[v]=;
if(match[v]==- || dfs(match[v])){
match[v]=u;
return ;
}
}
}
return ;
}
int hungary()
{
memset(match,-,sizeof(match));
int ret=;
for(int i=;i<=n;i++){
memset(vis,,sizeof(vis));
ret+=dfs(i);
}
return ret;
}
int main(void)
{
int k,a;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++) V[i].clear();
for(int i=;i<=n;i++){
scanf("%d",&k);
while(k--){
scanf("%d",&a);
V[i].push_back(a);
}
}
printf("%d\n",hungary());
}
return ;
}

poj 1274 The Perfect Stall (二分匹配)的更多相关文章

  1. poj 1274 The Prefect Stall - 二分匹配

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22736   Accepted: 10144 Description Far ...

  2. POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配

    两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...

  3. Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配)

    Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配) Description 农夫约翰上个 ...

  4. poj——1274 The Perfect Stall

    poj——1274   The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25709   A ...

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

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

  6. [题解]poj 1274 The Perfect Stall(网络流)

    二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络 ...

  7. POJ-1274The Perfect Stall,二分匹配裸模板题

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23313   Accepted: 103 ...

  8. poj 1274 The Perfect Stall【匈牙利算法模板题】

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20874   Accepted: 942 ...

  9. poj —— 1274 The Perfect Stall

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26274   Accepted: 116 ...

随机推荐

  1. 使用GeoServer发布shp数据为WMS服务和WFS服务

    使用GeoServer发布shp数据为WMS服务和WFS服务 1安装GeoServer 2使用GeoServer上传数据 3使用GeoServer发布数据为WMS和WFS 看完本教程,你将学会安装Ge ...

  2. 北京Uber优步司机奖励政策(1月24日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  3. 北京Uber优步司机奖励政策(12月16日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  4. 5 多进程copy文件

    1.如何进行开发? 2.版本1:程序大框架 #1.创建一个文件夹 #2.获取old文件夹中所有的文件名字 #3.使用多进程的方式copy原文件夹中的所有文件到新文件夹中 3.版本2:创建一个文件夹 1 ...

  5. python中的class正确用法

    class Dog: def __init__(self, name): self.name = name self.tricks = [] # creates a new empty list fo ...

  6. hdu2199Can you solve this equation?(解方程+二分)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  7. Qml-Dialog不能隐藏标题栏和按钮自定义

    在项目中,需要弹出一个对话框来完成用户输入的功能,为了考虑界面的同一,这里需要将原生自带的标题栏隐藏掉,换成自己写的 按照widget的写法,可以使用QDialog,但是qml与之对应的Dialog我 ...

  8. 消费者用nginx做负载均衡,提供者用zookeeper自带功能实现负载均衡

    公司的项目基于阿里的Dubbo微服务框架开发.为了符合相关监管部门的安全要求,公司购买了华东1.华东2两套异地服务器,一套是业务服务器,一套是灾备服务器.准备在这两套服务器上实现Dubbo的分布式服务 ...

  9. 项目实战:BBS+Blog项目开发

    01-博客系统之功能需求 02-博客系统之表结构设计1 03-博客系统之表结构设计2 04-博客系统之表结构设计3 05-博客系统之表结构设计4 06-博客系统之表机构设计5 07-博客系统之创建系统 ...

  10. <cfenv>(fenv.h) _c++11

    头文件 <cfenv>(fenv.h) c++11 浮点环境 这个头文件声明了一系列的函数和宏去访问浮点环境,以及特殊的类型. 浮点环境维护一系列的状态标志(status flags)和具 ...