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

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


Sample Output

 

Source


  这道题没有什么特别好说的,直接匈牙利算法不解释

Code:

 /**
* poj.org
* Problem#1274
* Accepted
* Time:16ms
* Memory:520k/540k
*/
#include<iostream>
#include<queue>
#include<set>
#include<map>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<stdarg.h>
#include<fstream>
#include<ctime>
using namespace std;
typedef bool boolean;
typedef class Edge {
public:
int end;
int next;
Edge():end(),next(){}
Edge(int end, int next):end(end),next(next){}
}Edge;
int *h;
int _count = ;
Edge* edge;
inline void addEdge(int from,int end){
edge[++_count] = Edge(end,h[from]);
h[from] = _count;
}
int result;
int *match;
boolean *visited;
boolean find(int node){
for(int i = h[node];i != ;i = edge[i].next){
if(visited[edge[i].end]) continue;
visited[edge[i].end] = true;
if(match[edge[i].end] == -||find(match[edge[i].end])){
match[edge[i].end] = node;
return true;
}
}
return false;
}
int n,m;
void solve(){
for(int i = ;i <= n;i++){
if(match[i] != -) continue;
memset(visited, false, sizeof(boolean) * (n + m + ));
if(find(i)) result++;
}
}
int buf;
int b;
boolean init(){
if(~scanf("%d%d",&n,&m)){
result = ;
visited = new boolean[(const int)(n + m + )];
match = new int[(const int)(n + m + )];
edge = new Edge[(const int)((n * m) + )];
h = new int[(const int)(n + m + )];
memset(h, , sizeof(int)*(n + m + ));
memset(match, -,sizeof(int)*(n + m + ));
for(int i = ;i ^ n;i++){
scanf("%d",&buf);
for(int j = ;j ^ buf;j++){
scanf("%d",&b);
addEdge(i + , b + n);
// addEdge(b + n, i + 1);
}
}
return true;
}
return false;
}
void freeMyPoint(){
delete[] visited;
delete[] match;
delete[] edge;
delete[] h;
}
int main(){
while(init()){
solve();
printf("%d\n",result);
freeMyPoint();
}
return ;
}

poj 1274 The Prefect Stall - 二分匹配的更多相关文章

  1. poj 1274 The Perfect Stall (二分匹配)

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

  2. [题解]poj 1274 The Prefect Stall

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

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

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

  4. 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 农夫约翰上个 ...

  5. poj——1274 The Perfect Stall

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

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

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

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

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

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

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

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

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

随机推荐

  1. 不移除通知的话,出现的bug

    没销毁的私聊控制器仍然监听到了通知,发送表情

  2. iOS开发tableView去掉顶部上部空表区域

    tableview中的第一个cell 里上部 有空白区域,大概64像素 在viewDidLoad中加入如下代码 self.automaticallyAdjustsScrollViewInsets = ...

  3. 洛谷P2634 聪聪可可 [国家集训队] 点分治/dp

    正解:点分治/dp 解题报告: 传送门! 这题有两个做法,都是我不擅长的就都说下好了QAQ 首先这题一看到就会想到点分治? 也确实可以用点分治,那就直接用点分治鸭 每次求出到当前根距离余数为0,1,2 ...

  4. Unity优化----drawcall系列

    本文由博主(国宝大熊猫)原创,转载请注明出处:http://www.cnblogs.com/xsln/p/5151951.html 知识普及:      *Drawcall影响的是CPU的效率.因为d ...

  5. kubernetes实战(十五):k8s使用helm持久化部署jenkins集成openLDAP登录

    1.基本概念 Jenkins在DevOps工具链中是核心的流程管理中心,负责串联系统的构建流程.测试流程.镜像制作流程.部署流程等,在持续集成中常用到的工具如下: Maven:源代码编译工具 Robo ...

  6. grunt学习三-bower(二)

    一.通过bower help 来展开bower的命令 Usage: bower <command> [<args>] [<options>] Commands: c ...

  7. 快捷键(SourceInsight)

    选择一块 : Ctrl+-选择一行 : Shift+F6到下一个函数 : 小键盘 +上一个函数 : 小键盘 -高亮当前单词 : Shift+F8回退.前进 alt + , alt + .最后一个窗口 ...

  8. shell date 获取昨天日期

    使用date -d 选项:  date  +"%Y%m%d" -d  "+n days"         今天的后n天日期       date  +" ...

  9. MySQL--教程

    登入登出 首先启动服务,然后 mysql -u root -p 命令输入密码登入. mysql退出三种方法:mysql > exit;mysql > quit;mysql > \q;

  10. 使用nvm管理node版本时,各个版本下公用npm安装的插件问题

    因为使用了NVM(node版本管理工具),所以在切换node版本的时候安装的插件不能共享使用,必须重新安装,导致不必要的工作量 所以我将npm(node包管理工具提取出来) 进行node版本之间的共享 ...