poj--1274--The Perfect Stall(匈牙利裸题)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 21868 | Accepted: 9809 |
Description
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
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
Sample Input
5 5
2 2 5
3 2 3 4
2 1 5
3 1 2 5
1 2
Sample Output
4
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define MAXN 100000+10
vector<int>G[10000];
int pipei[MAXN],used[MAXN],n,m;
int find(int u)
{
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i];
if(!used[v])
{
used[v]=1;
if(pipei[v]==-1||find(pipei[v]))
{
pipei[v]=u;
return 1;
}
}
}
return 0;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=1;i<=n;i++)
G[i].clear();
memset(pipei,-1,sizeof(pipei));
for(int i=1;i<=n;i++)
{
int t;
scanf("%d",&t);
while(t--)
{
int a;
scanf("%d",&a);
G[i].push_back(a);
}
}
int ans=0;
for(int i=1;i<=n;i++)
{
memset(used,0,sizeof(used));
ans+=find(i);
}
printf("%d\n",ans);
}
return 0;
}
poj--1274--The Perfect Stall(匈牙利裸题)的更多相关文章
- 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 农夫约翰上个 ...
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- poj——1274 The Perfect Stall
poj——1274 The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25709 A ...
- POJ 1274 The Perfect Stall
题意:有n只牛,m个牛圈(大概是),告诉你每只牛想去哪个牛圈,每个牛只能去一个牛圈,每个牛圈只能装一只牛,问最多能让几只牛有牛圈住. 解法:二分图匹配.匈牙利裸题…… 代码: #include< ...
- poj 1274 The Perfect Stall【匈牙利算法模板题】
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20874 Accepted: 942 ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- poj 1274 The Perfect Stall (二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17768 Accepted: 810 ...
- poj —— 1274 The Perfect Stall
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26274 Accepted: 116 ...
- POJ 1274 The Perfect Stall(二分图 && 匈牙利 && 最小点覆盖)
嗯... 题目链接:http://poj.org/problem?id=1274 一道很经典的匈牙利算法的题目: 将每只奶牛看成二分图中左边的点,将牛圈看成二分图中右边的点,如果奶牛看上某个牛圈,就将 ...
随机推荐
- 01--Java集合知识
一.Java集合概览 Java中集合分2大块,Collection和Map,分别代表不同功能的集合类对象,整体结构图如下: Collection├List│├LinkedList│├ArrayList ...
- jQuery——插件制作
1.$.fn.extend:扩展 jQuery 元素集来提供新的方法(通常用来制作插件),使用时是$('选择器').方法 2.$.extend:扩展jQuery对象本身,用来在jQuery命名空间上增 ...
- SQL基本操作——函数
函数的类型:在 SQL 中,基本的函数类型和种类有若干种.函数的基本类型是:Aggregate 函数.Scalar 函数. Aggregate 函数:操作面向一系列的值,并返回一个单一的值,下面是SQ ...
- The Standard SSL Handshake
The following is a standard SSL handshake when RSA key exchange algorithm is used: 1. Client Hello ...
- transform: scale(x,y)
作用: 1)缩放 2)反转 水平翻转:transform: scale(-1,1); 垂直翻转:transform: scale(1,-1); 水平垂直翻转: transform: scale(-1, ...
- Spring MVC起步(一)
下图展示了请求使用Spring MVC所经历的所有站点. 在请求离开浏览器时1,会带有用户请求内容的信息,至少会包含请求的URL.但是还可能包含其他的信息,如用户提交的表单. DispatcherSe ...
- 图表实现基于SVG或Canvas
Highcharts 基于SVG,方便自己定制,但图表类型有限. Echarts 基于Canvas,适用于数据量比较大的情况. D3.v3 基于SVG,方便自己定制:D3.v4支持Canvas+SVG ...
- common_functions.h:64:24: error: token ""__CUDACC_VER__ is no longer supported.
问题在复现工程https://github.com/google/hdrnet时出现. 现象: 解决: TensorFlow版本问题,升级到版本1.10.0之后,问题解决.
- 多目标跟踪笔记一:Finding the Best Set of K Paths Through a Trellis With Application to Multitarget Tracking
Abstract 本文提出一种寻找K最优路径的方法. k最优路径的定义:1.the sum of the metrics of all k paths in the set is minimized. ...
- 计蒜客 成绩统计 (Hash表)
链接 : Here! 思路 : 如果用 $STL$ 的 $map$ 或者是使用 $unordered\underline{}map$ 的话是会 $T$ 的, 所以得手写一个 $hash表$. 其实这个 ...