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 一道很经典的匈牙利算法的题目: 将每只奶牛看成二分图中左边的点,将牛圈看成二分图中右边的点,如果奶牛看上某个牛圈,就将 ...
随机推荐
- BFS小结
其实bfs本身不难,甚至不需要去学习,只要知道它的特性就可以写出来了.往往,bfs都是用递归做的.递归比循环更容易timeout.所以这次遇到一题bfs,卡时间的就悲剧了. PAT1076 #incl ...
- 00-SQLite的SQL语法
SQLite的SQL语法 SQLite库可以解析大部分标准SQL语言.但它也省去了一些特性并且加入了一些自己的新特性.这篇文档就是试图描述那些SQLite支持/不支持的SQL语法的.查看关键字列表. ...
- C# 获得星期几
var temp = System.DateTime.Today.ToString("dddd", new System.Globalization.CultureInfo(&qu ...
- 在对话框添加bitmap
CBitmap bitmap; //加载指定位图资源 Bmp图片ID bitmap.LoadBitmap(IDB_BITMAP1); //获取对话框上的句柄 图片控件ID CStatic *p = ( ...
- PHP采用301跳转方式防CC拦截
PHP采用301跳转方式防CC拦截 降低CC攻击的效果 <?php empty($_SERVER['HTTP_VIA']) or exit('Access Denied'); $second ...
- Mysql命令mysql:连接Mysql数据库
mysql命令格式: mysql -h主机地址 -u用户名 -p用户密码 1) 连接到本机上的MYSQL首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root -p, ...
- c++ list双向链表管理对象
#cat list.cc #include <cstdlib> #include <iostream> #include <stdio.h> using names ...
- 使用Oracle函数在创建表的时候自动加入生成的流水号 生成格式是:前缀+年月日+00000
CREATE OR REPLACE FUNCTION fn_no_make(v_type VARCHAR2, v_number_col VARCHAR2, v_table_name VARCHAR2) ...
- C++实现双人枪战游戏
//单机版枪战游戏,喜欢就拿走,把赞留下//by floatiy #include<iostream> #include<cstdio> #include<windows ...
- 单表:SQL语句关键字的执行顺序
表和数据: -- 创建表 CREATE TABLE `person` ( `id` ) NOT NULL AUTO_INCREMENT, `name` ) NOT NULL, `age` ) ', ` ...