主题链接:

id=1274">点击打开链接

呵呵

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#define N 2011
using namespace std; int lef[N], pn;//lef[v]表示Y集的点v 当前连接的点 , pn为x点集的点数
bool T[N]; //T[u] 表示Y集 u 是否已连接X集
vector<int>G[N]; //匹配边 G[X集].push_back(Y集) 注意G 初始化 bool match(int x){ // x和Y集 匹配 返回x点是否匹配成功
for(int i=0; i<G[x].size(); i++)
{
int v = G[x][i];
if(!T[v])
{
T[v] = true;
if(lef[v] == -1 || match( lef[v] )) //match(lef[v]) : 原本连接v的X集点 lef[v] 能不能和别人连,假设能 则v这个点就空出来和x连
{
lef[v] = x;
return true;
}
}
}
return false;
} int solve(){
int ans = 0;
memset(lef, -1, sizeof(lef));
for(int i = 1; i<= pn; i++)//X集匹配,X集点标号从 1-pn 匹配边是G[左点].size()
{
memset(T, 0, sizeof(T));
if( match( i ) ) ans++;
}
return ans;
}
int n,m;
int main(){
int i ,j;
while(~scanf("%d %d",&n,&m)){
for(i = 1; i <= n; i++)G[i].clear();
for(i = 1; i <= n; i++) {
int u; scanf("%d",&u);
while(u--){
scanf("%d",&j);
G[i].push_back(j);
}
}
pn = n;
printf("%d\n",solve());
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

POJ 1274 The Perfect Stall 水二分匹配的更多相关文章

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

    [题目链接] http://poj.org/problem?id=1274 [题目大意] 给出一些奶牛和他们喜欢的草棚,一个草棚只能待一只奶牛, 问最多可以满足几头奶牛 [题解] 奶牛和喜欢的草棚连线 ...

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

    Description Farmer John completed his new barn just last week, complete with all the latest milking ...

  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 (二分匹配)

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

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

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

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

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

随机推荐

  1. php可获取客户端信息

    <?php echo "<br>".$_SERVER['PHP_SELF'];#当前正在执行脚本的文件名,与 document root相关 echo " ...

  2. 与众不同 windows phone (14) - Media(媒体)之音频播放器, 视频播放器, 与 Windows Phone 的音乐和视频中心集成

    原文:与众不同 windows phone (14) - Media(媒体)之音频播放器, 视频播放器, 与 Windows Phone 的音乐和视频中心集成 [索引页][源码下载] 与众不同 win ...

  3. Swift - 移除页面视图上的所有元素

    下面代码可以遍历移除页面视图上的所有元件 1 2 3 4 5 6 //清空所有子视图 func clearViews() {     for v in self.view.subviews as [U ...

  4. ajax文本空输入显示用户信息

    一般文件代码 public void ProcessRequest (HttpContext context) { //获取主见值 string s = context.Request["u ...

  5. hdu 1007 最近点对问题(Splay解法)

    为什么要写这个题..经典啊,当然,别以为我用分治做的,不过主要思想还是那神奇的六个点共存(一个h*2h的矩形中最多能放下多少个点使得两两距离不超过h) 其实我是在这里看到的 http://commun ...

  6. ACM-计算几何之Quoit Design——hdu1007 zoj2107

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. C#之自己定义的implicit和explicit转换

    在类型转换时常会遇到隐式转换和显式转换.那我们自己定义的类型要怎样去定义隐式转换和显式转换?我们来看一段代码 public class Rational { private Int32 _inner_ ...

  8. 专注UI——有用技术:模糊搜索

    在如今的项目中.须要做模糊搜索,在曾经技术的基础上非常快得完毕了第一版.大家先看看第一版的效果,我们一会做评论: 0基础: 我们可能部分源代码(附件中会有所有源代码) <span style=& ...

  9. Pyocr 0.2 发布,Python 的 OCR 库 - 开源中国社区

    Pyocr 0.2 发布,Python 的 OCR 库 - 开源中国社区 Pyocr 0.2 发布,Python 的 OCR 库

  10. The tempfile module

    The tempfile module The tempfile module This module allows you to quickly come up with unique names ...