The Perfect Stall
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 21665   Accepted: 9735

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


#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>map[220];
int pipei[220],used[220];
int find(int x)
{
for(int i=0;i<map[x].size();i++)
{
int y=map[x][i];
if(!used[y])
{
used[y]=1;
if(!pipei[y]||find(pipei[y]))
{
pipei[y]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int num,y;
memset(pipei,0,sizeof(pipei));
for(int i=1;i<=n;i++)
{
map[i].clear();
scanf("%d",&num);
while(num--)
{
scanf("%d",&y);
map[i].push_back(y);
}
}
int sum=0;
for(int i=1;i<=n;i++)
{
memset(used,0,sizeof(used));
sum+=find(i);
}
printf("%d\n",sum);
}
return 0;
}

poj--1274--The Perfect Stall(最大匹配)的更多相关文章

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

  2. poj——1274 The Perfect Stall

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

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

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

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

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

  5. poj 1274 The Perfect Stall 解题报告

    题目链接:http://poj.org/problem?id=1274 题目意思:有 n 头牛,m个stall,每头牛有它钟爱的一些stall,也就是几头牛有可能会钟爱同一个stall,问牛与 sta ...

  6. poj —— 1274 The Perfect Stall

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

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

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

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

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

  9. [POJ] 1274 The Perfect Stall(二分图最大匹配)

    题目地址:http://poj.org/problem?id=1274 把每个奶牛ci向它喜欢的畜栏vi连边建图.那么求最大安排数就变成求二分图最大匹配数. #include<cstdio> ...

  10. POJ 1274 The Perfect Stall(二分图最大匹配)

    题意: N头牛M个牛棚,每只牛都有它自己指定的若干个它愿意呆的牛棚. 每个牛棚最多呆一头牛. 问最多可以满足多少头牛的愿望. 思路: 裸二分图最大匹配. 代码: int n,m; vector< ...

随机推荐

  1. Go Server Record

    Centos Setup Go yum install glibc-headers gcc-c++ # 一键安装shadowsocks 1. wget --no-check-certificate - ...

  2. poj3669 广搜

    //好久没刷题了,生疏了. 题意分析: 题意理解为在一个二维的正向坐标轴上,一个点(流星)连同它的上下左右的四个点会在某一个时刻被破坏.一个人在原点,问她到达安全区的最小时间是多少. 代码思路: 从原 ...

  3. 【Oracle】设置快速恢复区及reset快速恢复区

    快速恢复区 概念 是一个默认放置所有备份恢复操作有关文件的地方,包括:控制文件在线镜像.在线重做日志.归档日志.外来归档日志.控制文件镜像复制.数据文件镜像复制.RMAN备份片和闪回日志. 如果启用的 ...

  4. WEB笔记-让HTML5向下兼容的策略

    //给新标签增加块级元素声明 article,aside,dialog,figure,fotter,header,legend,nav,section{display:block} //添加css兹瓷 ...

  5. 通用功能类:改变WinForm窗体显示颜色

    一.显示窗体调用方法 protected override void OnLoad(EventArgs e)        {            MDIClientSupport.SetBevel ...

  6. mac 上执行 rm -rf /

    # 很可怕的指令,清空磁盘所有资料,千万不要用 sudo 尝试,吓的小心肝差掉跳出来 rm -rf / 无聊,想执行rm -rf /会怎样,想起没加sudo时对~/download执行提示权限不足,被 ...

  7. hadoop 安装问题总结

    安装启动步骤  [英语好的,直接手把手跟着来] http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/Sing ...

  8. Shell 在手分析服务器日志不愁

    转自:https://wujunze.com/server_logs_analysis.jsp 自己的小网站跑在阿里云的ECS上面,偶尔也去分析分析自己网站服务器日志,看看网站的访问量.看看有没有骇客 ...

  9. 简单说基于JWT和appkey、sercurtyKey的SSO、身份认证方案

    环境介绍, 一个大的系统由多个子系统组成.典型地,假设有一个平台,其上接入了多个应用.则有几个常见的问题需要处理, 1.SSO(包括单个应用退出时,需要处理为整个系统退出): 2.平台跳转到应用.及应 ...

  10. Windows10系统如何清除记录和关掉xbox录制

    在Windows的Xbox平台玩游戏时,总会发现以前玩过的许多游戏进度都保留着,麻烦的是白白的成就条让人感到相当的不爽,并且想删除还删不掉.某些当年一边玩一边录制的游戏,每当重新打开的时候都会弹出录制 ...