思路:

二分+最大流。
实现:

 #include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <assert.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
#include <sstream> #define N (1500 + 2)
#define M (N * N + 4 * N) typedef long long LL; using namespace std; struct edge
{
int v, cap, next;
};
edge e[M]; int head[N], level[N], cur[N];
int num_of_edges; /*
* When there are multiple test sets, you need to re-initialize before each
*/
void dinic_init(void)
{
num_of_edges = ;
memset(head, -, sizeof(head));
return;
} int add_edge(int u, int v, int c1, int c2)
{
int& i = num_of_edges; assert(c1 >= && c2 >= && c1 + c2 >= ); // check for possibility of overflow
e[i].v = v;
e[i].cap = c1;
e[i].next = head[u];
head[u] = i++; e[i].v = u;
e[i].cap = c2;
e[i].next = head[v];
head[v] = i++;
return i;
} void print_graph(int n)
{
for (int u = ; u < n; u++)
{
printf("%d: ", u);
for (int i = head[u]; i >= ; i = e[i].next)
{
printf("%d(%d)", e[i].v, e[i].cap);
}
printf("\n");
}
return;
} /*
* Find all augmentation paths in the current level graph
* This is the recursive version
*/
int dfs(int u, int t, int bn)
{
if (u == t) return bn;
int left = bn;
for (int &i = cur[u]; i >= ; i = e[i].next)
{
int v = e[i].v;
int c = e[i].cap;
if (c > && level[u] + == level[v])
{
int flow = dfs(v, t, min(left, c));
if (flow > )
{
e[i].cap -= flow;
e[i ^ ].cap += flow;
cur[u] = i;
left -= flow;
if (!left) break;
}
}
}
if (left > ) level[u] = ;
return bn - left;
} bool bfs(int s, int t)
{
memset(level, , sizeof(level));
level[s] = ;
queue<int> q;
q.push(s);
while (!q.empty())
{
int u = q.front();
q.pop();
if (u == t) return true;
for (int i = head[u]; i >= ; i = e[i].next)
{
int v = e[i].v;
if (!level[v] && e[i].cap > )
{
level[v] = level[u] + ;
q.push(v);
}
}
}
return false;
} LL dinic(int s, int t)
{
LL max_flow = ; while (bfs(s, t))
{
memcpy(cur, head, sizeof(head));
max_flow += dfs(s, t, INT_MAX);
}
return max_flow;
} vector<int> v[N];
int n, m;
bool check(int x)
{
dinic_init();
for (int i = ; i <= n; i++)
{
for (int j = ; j < v[i].size(); j++)
{
add_edge(i, v[i][j] + n + , , );
}
}
for (int i = ; i <= n; i++)
add_edge(, i, , );
for (int j = n + ; j <= n + m; j++)
{
add_edge(j, n + m + , x, );
}
return dinic(, n + m + ) == n;
} int main()
{
while (cin >> n >> m, n || m)
{
getchar();
string s, name;
int group;
for (int i = ; i <= n; i++) v[i].clear();
for (int i = ; i <= n; i++)
{
getline(cin, s);
stringstream ss(s);
ss >> name;
while (ss >> group)
{
v[i].push_back(group);
}
}
int l = , r = n, ans = n;
while (l <= r)
{
int m = (l + r) >> ;
if (check(m))
{
r = m - ; ans = m;
}
else l = m + ;
}
cout << ans << endl;
}
return ;
}

poj2289 Jamie's Contact Groups的更多相关文章

  1. POJ2289 Jamie's Contact Groups —— 二分图多重匹配/最大流 + 二分

    题目链接:https://vjudge.net/problem/POJ-2289 Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 6 ...

  2. POJ2289 Jamie's Contact Groups(二分图多重匹配)

    Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 7721   Accepted: ...

  3. POJ2289:Jamie's Contact Groups(二分+二分图多重匹配)

    Jamie's Contact Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/ ...

  4. POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups / HDU 1699 Jamie's Contact Groups / SCU 1996 Jamie's Contact Groups (二分,二分图匹配)

    POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups ...

  5. Jamie's Contact Groups POJ - 2289(多重匹配 最大值最小化 最大流)

    Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 8567   Accepted: ...

  6. POJ 2289 Jamie's Contact Groups 二分图多重匹配 难度:1

    Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 6511   Accepted: ...

  7. poj 2289 Jamie's Contact Groups【二分+最大流】【二分图多重匹配问题】

    题目链接:http://poj.org/problem?id=2289 Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K ...

  8. POJ 2289——Jamie's Contact Groups——————【多重匹配、二分枚举匹配次数】

    Jamie's Contact Groups Time Limit:7000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  9. Poj 2289 Jamie's Contact Groups (二分+二分图多重匹配)

    题目链接: Poj 2289 Jamie's Contact Groups 题目描述: 给出n个人的名单和每个人可以被分到的组,问将n个人分到m个组内,并且人数最多的组人数要尽量少,问人数最多的组有多 ...

随机推荐

  1. 条款九: 避免隐藏标准形式的new

    因为内部范围声明的名称会隐藏掉外部范围的相同的名称,所以对于分别在类的内部和全局声明的两个相同名字的函数f来说,类的成员函数会隐藏掉全局函数 class x { public: void f(); / ...

  2. 【c++】【转】如何只在heap上创建对象,如何只在stack上建立对象?

    http://www.cnblogs.com/chio/archive/2007/10/23/934335.html http://blog.csdn.net/szchtx/article/detai ...

  3. Flink内存管理源代码解读之基础数据结构

    概述 在分布式实时计算领域,怎样让框架/引擎足够高效地在内存中存取.处理海量数据是一个非常棘手的问题.在应对这一问题上Flink无疑是做得非常杰出的,Flink的自主内存管理设计或许比它自身的知名度更 ...

  4. quick-cocos2d-x游戏开发【1】——引擎结构总览和创建项目

    好吧,我还是忍不住想写点关于quick的学习笔记,确实网上关于它的教程太少太少了,简单把自己的所学所得分享一下,有不正确之处还请拍砖. 首先下载引擎包.触控收购quick之后.如今cocos中文站的主 ...

  5. 系统的BIOS与系统安装

    今天偶尔看到个介绍电脑BIOS的与各种本子安装系统的介绍:(记录一下) 网络地址:http://blog.sina.com.cn/s/blog_4a1faae60102dyek.html

  6. 【智能家居篇】wifi网络结构(下)

    转载请注明出处:http://blog.csdn.net/Righthek 谢谢. 因为WIFI网络具有移动性,同一时候WIFI以无线电波作为传输媒介,这样的媒介本质上是开放的,且easy被拦截,不论 ...

  7. SpringMVC学习指南-Spring框架

    Spring框架主要使用依赖注入.实际上,很多牛叉的框架如Google的Guice都是使用依赖注入. ------------------------------------------------- ...

  8. HTML <iframe> 标签的 src 属性

    HTML <iframe> 标签的 src 属性 <iframe src="/index.html"> <p>Your browser does ...

  9. sql 查询如何将结果集 输出为一段字符串?

    文件id集合 文件表. SELECT CONCAT('2323',(SELECT 'dsfsd'),'232323'); SELECT CONCAT('2323',(SELECT file_ids F ...

  10. Android系统定制----删除系统锁屏功能【转】

    本文转载自:http://blog.csdn.net/morixinguan/article/details/56675914 frameworks/base/packages/SettingsPro ...