Dining
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 22572   Accepted: 10015

Description

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

Farmer John has cooked fabulous meals for his cows, but he forgot to check his menu against their preferences. Although he might not be able to stuff everybody, he wants to give a complete meal of both food and drink to as many cows as possible.

Farmer John has cooked F (1 ≤ F ≤ 100) types of foods and prepared D (1 ≤ D ≤ 100) types of drinks. Each of his N (1 ≤ N ≤ 100) cows has decided whether she is willing to eat a particular food or drink a particular drink. Farmer John must assign a food type and a drink type to each cow to maximize the number of cows who get both.

Each dish or drink can only be consumed by one cow (i.e., once food type 2 is assigned to a cow, no other cow can be assigned food type 2).

Input

Line 1: Three space-separated integers: N, F, and D
Lines 2..N+1: Each line i starts with a two integers Fi and Di, the number of dishes that cow i likes and the number of drinks that cow i likes. The next Fi integers denote the dishes that cow i will eat, and the Di integers following that denote the drinks that cow i will drink.

Output

Line 1: A single integer that is the maximum number of cows that can be fed both food and drink that conform to their wishes

Sample Input

4 3 3
2 2 1 2 3 1
2 2 2 3 1 2
2 2 1 3 1 2
2 1 1 3 3

Sample Output

3

C/C++:

 #include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
const int my_max = ; int my_map[my_max][my_max], my_cow, my_food, my_drink, my_source,
my_sink, n, my_dis[my_max]; int my_dfs(int step, int ans)
{
if (step == my_sink) return ans; int temp = ans;
for (int i = ; i < n && temp; ++ i)
{
if (my_dis[i] + == my_dis[step] && my_map[step][i])
{
int t = my_dfs(i, min(ans, my_map[step][i]));
ans -= t;
my_map[step][i] -= t;
my_map[i][step] += t;
}
}
return temp - ans;
} bool my_bfs()
{
memset(my_dis, -, sizeof(my_dis));
my_dis[my_sink] = ;
queue <int> Q;
Q.push(my_sink);
while (!Q.empty())
{
int my_temp = Q.front();
for (int i = ; i < n; ++ i)
{
if (my_dis[i] == - && my_map[i][my_temp])
{
my_dis[i] = my_dis[my_temp] + ;
Q.push(i);
}
}
if (my_temp == my_source) return true;
Q.pop();
}
return false;
} int my_dinic()
{
int my_max_flow = ;
while (my_bfs())
my_max_flow += my_dfs(my_source, INF); return my_max_flow;
} int main()
{
while (~scanf("%d%d%d", &my_cow, &my_food, &my_drink))
{
my_source = , my_sink = my_food + *my_cow + my_drink;
for (int i = ; i <= my_food; ++ i) my_map[my_source][i] = ;
for (int i = ; i <= my_cow; ++ i) my_map[my_food + i][my_food + my_cow + i] = ;
for (int i = ; i <= my_drink; ++ i) my_map[my_food + *my_cow + i][my_sink] = ; for (int i = ; i <= my_cow; ++ i)
{
int my_food_num, my_drink_num;
scanf("%d%d", &my_food_num, &my_drink_num);
while (my_food_num --)
{
int my_temp;
scanf("%d", &my_temp);
my_map[my_temp][my_food + i] = ;
}
while (my_drink_num --)
{
int my_temp;
scanf("%d", &my_temp);
my_map[my_food + my_cow + i][my_food + * my_cow + my_temp] = ;
}
} n = my_sink + ;
printf("%d\n", my_dinic());
}
return ;
}

help

poj 3281 Dining (Dinic)的更多相关文章

  1. POJ 3281 Dining (网络流)

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

  2. POJ 3281 Dining(最大流)

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

  3. POJ 3281 网络流dinic算法

    B - Dining Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

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

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

  5. POJ 3281 Dining(最大流+拆点)

    题目链接:http://poj.org/problem?id=3281 题目大意:农夫为他的 N (1 ≤ N ≤ 100) 牛准备了 F (1 ≤ F ≤ 100)种食物和 D (1 ≤ D ≤ 1 ...

  6. POJ 3281 Dining(最大流)

    http://poj.org/problem?id=3281 题意: 有n头牛,F种食物和D种饮料,每头牛都有自己喜欢的食物和饮料,每种食物和饮料只能给一头牛,每头牛需要1食物和1饮料.问最多能满足几 ...

  7. POJ 3281 Dining(网络流拆点)

    [题目链接] http://poj.org/problem?id=3281 [题目大意] 给出一些食物,一些饮料,每头牛只喜欢一些种类的食物和饮料, 但是每头牛最多只能得到一种饮料和食物,问可以最多满 ...

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

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

  9. POJ 3281 Dining

    Dining Description Cows are such finicky eaters. Each cow has a preference for certain foods and dri ...

随机推荐

  1. 上手Typescript,让JavaScript适用于大型应用开发

    Typescript Typescript是一个基于静态类型的,能编译为JavaScript的JavaScript的超集.也就是说任何JavaScript都可以看成是Typescript,IDE能够更 ...

  2. ‎Cocos2d-x 学习笔记(11.10) Spawn

    Spawn让多个action同时执行. Spawn有多种不同的create方法,最终都调用了createWithTwoActions(FiniteTimeAction *action1, Finite ...

  3. Redis 消息队列的实现

    概述 Redis实现消息队列有两种形式: 广播订阅模式:基于Redis的 Pub/Sub 机制,一旦有客户端往某个key里面 publish一个消息,所有subscribe的客户端都会触发事件 集群订 ...

  4. 玩转OneNET物联网平台之MQTT服务① —— OneNetMqtt全方位调试

    授人以鱼不如授人以渔,目的不是为了教会你具体项目开发,而是学会学习的能力.希望大家分享给你周边需要的朋友或者同学,说不定大神成长之路有博哥的奠基石... QQ技术互动交流群:ESP8266&3 ...

  5. ArcGIS Engine简单图形绘制功能的实现(点、线、面)

    我们添加点.线.面来实现图形的编辑需要使用Geometry对象类. Point(点) 是一个0维的几何图形,具有X.Y坐标值,以及可选的属性,如高程值(Z值).度量值(M值).ID值等,可用于描述需要 ...

  6. The usage of Markdown---代码块

    目录 1. 序言 2. 代码块 3. 引用中的代码 4. 列表中的代码块 更新时间:2019.09.14 1. 序言   在写技术博客的时候,我们常常需要添加一下代码块用来做演示说明,实际上在这篇博客 ...

  7. python中的可变数据类型和不可变数据类型

    1.不可变数据类型:数值.字符串.元组 不允许变量的值发生变化,如果变量的值变化了,那么就是新建了一个对象:对于相同值的对象,在内存中只有一个对象. 2.可变数据类型:列表.字典 允许变量的值发生变化 ...

  8. 痞子衡嵌入式:飞思卡尔i.MX RTyyyy系列MCU硬件那些事(2.2)- 在串行NOR Flash XIP调试原理

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是飞思卡尔i.MX RTyyyy系列EVK在串行NOR Flash调试的原理. 本文是i.MXRT硬件那些事系列第二篇的续集,在第二篇首集 ...

  9. js实现的几种继承方式

    他山之石,可以攻玉,本人一直以谦虚的态度学他人之所长,补自己之所短,望各位老师指正! 拜谢 js几种继承方式,学习中的总结: 所谓的继承是为了继承共有的属性,减少不必要代码的书写 第一种:借用构造函数 ...

  10. C++智能指针类型转换

    #include <iostream> #include <memory> struct Base { int a; virtual void f() const { std: ...