分析

数学模型是三个集合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. Python包管理工具setuptools详解及entry point

    1.什么是setuptools? setuptools是Python distutils增强版的集合,它可以帮助我们更简单的创建和分发Python包,尤其是拥有依赖关系的.用户在使用setuptool ...

  2. [CentOS7] 设置开机启动方式(图形界面或命令行)

    由于CenOS之前一直都是通过修改inittab文件来修改开机启动模式,于是 通过 vim /etc/inittab 打开inittab来查看 如上所示,CentOS 7由于使用systemd而不是i ...

  3. Codeforces Round #558 (Div. 2)B(SET,模拟)

    #include<bits/stdc++.h>using namespace std;int a[100007];int cnt[100007];int main(){    int n; ...

  4. 解读人:李琼,Metabolic profiling of tumors, sera and skeletal muscles from an orthotopic murine model of gastric cancer associated-cachexia(胃癌相关恶病质的原位小鼠模型中肿瘤,血清和骨骼肌的代谢谱分析)

    发表时间:(2019年4月) IF:3.950 单位: 厦门大学 厦门理工大学 物种:小鼠的肿瘤,血清和骨骼肌 技术:核磁共振代谢组学分析 一. 概述:(用精炼的语言描述文章的整体思路及结果) 本研究 ...

  5. Python 软件热更新

    Python 软件热更新 本篇文章涉及技术知识如下: Redis threading 多线程 PyQt5 importlib 热更新 场景 咱们在平时运行一些长时间都会一直运行的软件(如:某些云同步软 ...

  6. 分层图最短路【bzoj2834】: 回家的路

    分层图最短路[bzoj2834]: 回家的路 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2834 这道题难在建边. 自己写的时候想到了 ...

  7. 分层图最短路【bzoj2763】: [JLOI2011]飞行路线

    bzoj2763: [JLOI2011]飞行路线 Description Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0 ...

  8. 关于状态压缩DP以及状态压缩

    首先要明确:状态压缩是利用数字来代表一组序列的方法,从而降低序列访问的复杂度,本质上跟HASH有着差不多的思想,但是其实就是数位运算的一种 定义:集合中共有N个数字,其中每个数字均小于K,能么我们可以 ...

  9. spring boot与 spring.factories

    spring boot启动加载过程 META-INF下面的spring.factories 解析@Configuration https://www.jianshu.com/p/346cac67bfc ...

  10. 转 mysql 下载 以及安装

    https://blog.csdn.net/kerafan/article/details/78001849 一.MySQL 各个版本区别 ,(都需要编译的 ) 1.MySQL Community S ...