分析

数学模型是三个集合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. ERROR 1010 (HY000): Error dropping database (can't rmdir './nsd', errno: 39)

    在删除数据库的时候报标题所示错误 mysql> drop database test; ERROR 1010 (HY000): Error dropping database (can't rm ...

  2. 洛谷P3478 [POI2008]STA-Station

    P3478 [POI2008]STA-Station 题目描述 The first stage of train system reform (that has been described in t ...

  3. SKlearn中分类决策树的重要参数详解

    学习机器学习童鞋们应该都知道决策树是一个非常好用的算法,因为它的运算速度快,准确性高,方便理解,可以处理连续或种类的字段,并且适合高维的数据而被人们喜爱,而Sklearn也是学习Python实现机器学 ...

  4. windows系统IIS7环境下如何部署MVC项目

    首先打开IIS:第一步:添加MVC程序映射 打开其中的:处理程序映射,如下图: 点击界面右边操作中的:添加脚本映射,弹出下图: 请求路径:*           可执行文件:c:/Windows/Mi ...

  5. VMware Workstation 安装以及Linux虚拟机安装 指北

    最近有挺多小伙伴跟我说起虚拟机这个东西,所以,今天就给大家写一篇虚拟机安装使用指北吧. 虚拟机(英语:virtual machine),在计算机科学中的体系结构里,是指一种特殊的软件,可以在计算机平台 ...

  6. 高斯消元法的C++简单实现

    高斯消元法 首先,我们导入几个概念. 定义1: 一个矩阵称为阶梯形(行阶梯形),若它有以下三个性质: 1.每一非零行在每一零行之上: 2.某一行的先导元素所在的列位于前一行先导元素的后面: 3.某一行 ...

  7. C# JObject将json字符串转为json对象

    static void Main(string[] args) { string json = "{\"name\": \"测试\",\"m ...

  8. Docker从入门到实战(三)

    Docker从入门到实战(三) 一:安装Docker 1. linux系统脚本安装 Docker基于linux容器技术,面向服务器端,Docker只能安装运行在64位计算机上(社区有对32位的支持), ...

  9. nginx配置openssl证书

    引用出处: https://blog.csdn.net/liuchunming033/article/details/48470575 证书生成基本步骤: 生成私钥(.key)-->生成证书请求 ...

  10. JAVA内存模型(Java Memory Model ,JMM)

    http://blog.csdn.net/hxpjava1/article/details/55189077 JVM有主内存(Main Memory)和工作内存(Working Memory),主内存 ...