POJ-3281 Dining Dinic最大流
来源:互联网 发布:js 创建key value数组 编辑:程序博客网 时间:2024/05/29 11:53
MMP
Dining
Time Limit: 2000MS Memory Limit: 65536K
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
Hint
One way to satisfy three cows is:
Cow 1: no meal
Cow 2: Food #2, Drink #2
Cow 3: Food #1, Drink #1
Cow 4: Food #3, Drink #3
The pigeon-hole principle tells us we can do no better since there are only three kinds of food or drink. Other test data sets are more challenging, of course.
Source
USACO 2007 Open Gold
劳资调了一下午。。。。
傻逼错误
就是一个简单的建图, 拆牛。。。
我的Dinic没有错!!!
# include <queue># include <cctype># include <cstdio># include <cstring># define N 100005inline void readIn ( int& x ) { register char c ; while ( ! isdigit ( c = getchar ( ) ) ) ; for ( x = -48 + c ; isdigit ( c = getchar ( ) ) ; x = x * 10 + c - 48 ) ;}template < class T > inline T min ( T a, T b ) { return a > b ? b : a ; }class Network {private : struct edge { int to, w, nxt ; edge ( ) { } edge ( int to, int w, int nxt ) : to ( to ), w ( w ), nxt ( nxt ) { } } g [N << 1] ; int head [N], cur [N], ecnt ; int S, T , dep [N] ; inline int Dfs ( int u, int a ) { if ( u == T || ! a ) return a ; int flow = 0, v, f ; for ( int& i = cur [u] ; i ; i = g [i].nxt ) { v = g [i].to ; if ( dep [v] == dep [u] + 1 ) { f = Dfs ( v, min ( g [i].w, a - flow ) ) ; g [i].w -= f, g [i ^ 1].w += f ; flow += f ; if ( a == flow ) return a ; } } if ( ! flow ) dep [u] = -1 ; return flow ; } inline bool Bfs ( int S, int T ) { static std :: queue < int > q ; memset ( dep, 0, sizeof ( int ) * ( T + 1 ) ) ; dep [S] = 1 ; q.push ( S ) ; while ( ! q.empty ( ) ) { int u = q.front ( ) ; q.pop ( ) ; for ( int i = head [u] ; i ; i = g [i].nxt ) { int v = g [i].to ; if ( g [i].w && ! dep [v] ) { dep [v] = dep [u] + 1 ; q.push ( v ) ; } } } return dep [T] ; }public : Network ( ) { ecnt = 1 ; } inline void Add_edge ( int u, int v, int w ) { g [++ ecnt] = edge ( v, w, head [u] ) ; head [u] = ecnt ; g [++ ecnt] = edge ( u, 0, head [v] ) ; head [v] = ecnt ; } inline int Dinic ( int S, int T ) { this -> S = S, this -> T = T ; int rt = 0 ; while ( Bfs ( S, T ) ) { memcpy ( cur, head, sizeof ( int ) * ( T + 1 ) ) ; rt += Dfs ( S, 0x3f3f3f3f ) ; } return rt ; }} Lazer ;int n, f, d ;int main ( ) { readIn ( n ) ; readIn ( f ) ; readIn ( d ) ; const int nn = n << 1 ; const int S = 0, T = nn + f + d + 1 ; for ( int i = 1 ; i <= n ; ++ i ) { static int fi, di ; readIn ( fi ) ; readIn ( di ) ; while ( fi -- ) { static int x ; readIn ( x ) ; Lazer.Add_edge ( nn + x, i, 1 ) ; } Lazer.Add_edge ( i, i + n, 1 ) ; while ( di -- ) { static int x ; readIn ( x ) ; Lazer.Add_edge ( i + n, nn + f + x, 1 ) ; } } for ( int i = 1 ; i <= f ; ++ i ) Lazer.Add_edge ( S, nn + i, 1 ) ; for ( int i = 1 ; i <= d ; ++ i ) Lazer.Add_edge ( nn + f + i, T, 1 ) ; return printf ( "%d\n", Lazer.Dinic ( S, T ) ), 0 ;}
- poj 3281 Dining (最大流Dinic)
- POJ 3281 Dining(最大流-Dinic)
- POJ-3281 Dining Dinic最大流
- POJ 3281 Dining (网络流最大流 拆点建图 EK Dinic)
- POJ 3281 Dining(最大流dinic&&SAP)
- (POJ 3281)Dining --最大流,匹配建图,Dinic
- poj 3281 Dining 最大流dinic 模板题
- Dining-最大流/Dinic
- POJ 3281 Dining dinic
- Poj 3281 Dining【最大流Dinic+建图+谨慎思维】好题
- poj 3281 Dining 【最大流】
- poj 3281 Dining(最大流)
- POJ 3281 Dining(最大流)
- poj 3281 Dining 最大流
- poj 3281 Dining (最大流)
- poj 3281 Dining 【最大流】
- poj 3281 Dining (最大流)
- poj 3281 Dining 最大流
- 面向对象复习一
- TCP协议中的三次握手和四次挥手(图解)
- 常用设计模式之简单工厂模式
- 如何js正则表达式判断ip地址的合法性?
- 编程练习二维数组 java
- POJ-3281 Dining Dinic最大流
- codeforces 579D(35/600)
- Android通过HTTP协议实现断点续传下载
- Mongodb 删除重复数据的几个方法
- Unity获取当前城市天气
- Android常用框架----网络请求系列框架
- 项目提示:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactor
- CSS3转换
- 机器学习笔记六