分析

数学模型是三个集合A,B,C,(a,b,c)构成一个匹配。因为图一个点只能匹配一次,把a拆点a',a",

在可以匹配的点上连边,s - b - a' - a" - c - t,然后最大流就好了。

/*********************************************************
* ------------------ *
* author AbyssalFish *
**********************************************************/
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
using namespace std; typedef long long ll; const int maxv = , maxe = +;
int hd[maxv],to[maxe],nx[maxe],ec, cap[maxe];
#define eachEage int i = hd[u]; i; i = nx[i]
void add(int u,int v,int cp)
{
nx[++ec] = hd[u];
to[ec] = v;
cap[ec] = cp;
hd[u] = ec;
}
void Add(int u,int v,int cp = )
{
add(u,v,cp);
add(v,u,);
} int S,T; int lv[maxv];
bool vis[maxv];
int que[maxv]; bool bfs()
{
memset(vis,,sizeof(vis));
int *q = que, l = , r = ;
lv[q[r++] = S] = ; vis[S] = true;
while(l<r){
int u = q[l++];
for(eachEage){
int v = to[i];
if(!vis[v] && cap[i]){
lv[v] = lv[u] + ;
vis[v] = true;
q[r++] = v;
}
}
}
return vis[T];
} int cur[maxv]; int aug(int u,int a)
{
if(u == T || !a) return a;
int flow = ,f;
for(int &i = cur[u]; i; i = nx[i]){
int v = to[i];
if(lv[v] == lv[u]+ && (f = aug(v,min(a,cap[i])))){
flow += f; a -= f;
cap[i] -= f; cap[i^] += f;
if(!a) break;
}
}
return flow;
} int maxFlow()
{
int flow = ;
while(bfs()){
memcpy(cur,hd,sizeof(int)*(T+));
flow += aug(S,<<);
}
return flow;
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
ec = ;
int N, F, D; scanf("%d%d%d",&N,&F,&D);
int N2 = N*, N2F = N2+F;
S = ; T = N2F+D+;
for(int i = ; i <= N; i++){
int Fi, Di, x; scanf("%d%d",&Fi,&Di);
while(Fi--){
scanf("%d", &x);
Add(N2+x,i);
}
Add(i,N+i);
while(Di--){
scanf("%d", &x);
Add(N+i,N2F+x);
}
}
for(int i = ; i <= F; i++) Add(S,N2+i);
for(int i = ; i <= D; i++) Add(N2F+i,T);
printf("%d\n", maxFlow());
return ;
}

POJ 3281 Dining(网络流最大匹配)的更多相关文章

  1. poj 3281 Dining 网络流-最大流-建图的题

    题意很简单:JOHN是一个农场主养了一些奶牛,神奇的是这些个奶牛有不同的品味,只喜欢吃某些食物,喝某些饮料,傻傻的John做了很多食物和饮料,但她不知道可以最多喂饱多少牛,(喂饱当然是有吃有喝才会饱) ...

  2. POJ 3281 Dining 网络流最大流

    B - DiningTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.ac ...

  3. POJ 3281 Dining (网络流之最大流)

    题意:农夫为他的 N (1 ≤ N ≤ 100) 牛准备了 F (1 ≤ F ≤ 100)种食物和 D (1 ≤ D ≤ 100) 种饮料.每头牛都有各自喜欢的食物和饮料, 而每种食物或饮料只能分配给 ...

  4. POJ 3281 Dining[网络流]

    Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will c ...

  5. POJ 3281 Dining (网络流构图)

    [题意]有F种食物和D种饮料,每种食物或饮料只能供一头牛享用,且每头牛只享用一种食物和一种饮料.现在有N头牛,每头牛都有自己喜欢的食物种类列表和饮料种类列表,问最多能使几头牛同时享用到自己喜欢的食物和 ...

  6. POJ 3281 Dining(网络流-拆点)

    Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will c ...

  7. POJ 3281 Dining (网络流)

    POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...

  8. POJ 3281 Dining(最大流)

    POJ 3281 Dining id=3281" target="_blank" style="">题目链接 题意:n个牛.每一个牛有一些喜欢的 ...

  9. poj 3281 Dining (最大网络流)

    题目链接: http://poj.org/problem?id=3281 题目大意: 有n头牛,f种食物,d种饮料,第i头牛喜欢fi种食物和di种饮料,每种食物或者饮料被一头牛选中后,就不能被其他的牛 ...

随机推荐

  1. 洛谷P2580(trie)

    第一行一个整数 n,表示班上人数.接下来 n 行,每行一个字符串表示其名字(互不相同,且只含小写字母,长度不超过 50).第 n+2 行一个整数 m,表示教练报的名字.接下来 m 行,每行一个字符串表 ...

  2. Repeater+AspNetPager+Ajax留言板

    最近想要巩固下基础知识,于是写了一个比较简单易懂实用的留言板. 部分样式参考了CSDN(貌似最近一直很火),部分源码参照了Alexis. 主要结构: 1.前期准备 2.Repeater+AspNetP ...

  3. [Xcode 实际操作]三、视图控制器-(12)在Storyboard中使用集合控件

    目录:[Swift]Xcode实际操作 本文将演示集合控件在故事板中的使用. 在控制器根视图上点击鼠标,以选择该根视图. 现在往根视图中添加一个集合视图. 点击[库面板]图标,打开控件库面板 在控件库 ...

  4. 转载 jQuery 整理的很详细,基本都在里面

    jQuery 函数     CSS 函数 $(a).css(name)     获取name属性值 $(a). css(name,value)      设置name的属性值 $(a).css({}) ...

  5. git教程1-gitlab部署

    https://about.gitlab.com/install/#centos-7 https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/ gitla ...

  6. css奇技淫巧—border-radius

    官方介绍: 浏览器支持:IE9+, Firefox 4+, Chrome, Safari 5+,和Opera支持border-radius属性. border-radius 属性是一个最多可指定四个 ...

  7. Linux得到某个文件夹内文件的个数

    panonum=$(find . -type f | wc -l)

  8. set<int> 的用法

    博客学习:https://blog.csdn.net/yas12345678/article/details/52601454 介绍一下 *max_element(a,a+n)  求取数组最大的元素  ...

  9. Java面向对象_对象内存分析—值传递和引用传递

    对象内存分析,我一直学的比较模糊,今天抽空整理一下,希望能理清. 先说一下,内存分析从何而来,这对于我们这些刚接触java的人来说都比较模糊,就从new关键字说起吧. new关键字表示创建一个对象或者 ...

  10. ${openid_wx} el解析式放入url的“”里才起作用。

    window.location.href="${ctx }/wx/reservation/content?shopid="+shopid+"&&openi ...