博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1274 The Perfect Stall(二分图匹配)
阅读量:6852 次
发布时间:2019-06-26

本文共 1890 字,大约阅读时间需要 6 分钟。

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 52 2 53 2 3 42 1 53 1 2 51 2

 

Sample Output

4

 

Source

 
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 #define N 206 9 int n,m;10 vector
v[N];11 int vis[N];12 int match[N];13 14 bool dfs(int u){15 for(int i=0;i
View Code

 

转载地址:http://hwyyl.baihongyu.com/

你可能感兴趣的文章
CentOS 6.4 安装python2.7/mysqldb/ipython
查看>>
hive0.11 hiveserver custom认证bug
查看>>
Windows Phone SDK 8.0 新特性-Speech
查看>>
VS~单步调试DLL
查看>>
MyEclipse环境下Hibernate入门实例
查看>>
VC+CSocket文件传送示例
查看>>
职业生涯中的选择时机非常重要,各种条件还没成熟时的时候,因为诱惑而贸然行事,只会得到适得其反的结果...
查看>>
[WebDevelopment]搜索引擎优化(SEO)工具包
查看>>
Symbian OS开发入门(二) :VS2003环境下Symbian工程的导入与建立
查看>>
RequiredFieldValidator 根据group组来触发验证
查看>>
[AR]ImageTarget(图像识别)
查看>>
[C++] socket -9[匿名管道]
查看>>
移动端网络优化
查看>>
测试并发应用(二)监控Phaser类
查看>>
云上游戏数据分析实践
查看>>
前端如何实现数据双向绑定
查看>>
视频码率那些事
查看>>
Android仿网易云音乐:留声机效果
查看>>
vue-cli项目升级webpack4踩坑
查看>>
Python爬虫框架,内置微博、自如、豆瓣图书、拉勾、拼多多等规则
查看>>