思路:

二分+最大流。
实现:

 #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. HTML5 全屏化操作功能

    由于项目中用到了全屏化挫折功能,查看了API后写了一个简单的全屏化model <!DOCTYPE html> <html> <head> <meta http ...

  2. Ubuntu 16.04安装QtCharts时报错:'qtConfig' is not a recognized test function.

    错误: 'qtConfig' is not a recognized test function. 解决方法: 其实5.9分支的版本有问题,转成5.7分支即可. git clone https://g ...

  3. TensorFlow-GPU环境配置之三——安装bazel

    TensorFlow的源码需要使用bazel进行编译,所以需要安装bazel构建工具 1.安装JDK 8 sudo add-apt-repository ppa:webupd8team/java su ...

  4. jenkinsapi出现HTTPConnectionPool Max retires exceeded异常

    python项目通过使用jenkinsapi远程控制jenkins jenkinsapi使用的远程连接方法是requests包,requests包又使用了urllib3,urllib3又引用了http ...

  5. symfony 使用原始sql

    $this->get('database_connection')->fetchAll('select * from book where book.id=3')

  6. windows server 证书的颁发与IIS证书的使用 Dapper入门使用,代替你的DbSQLhelper Asp.Net MVC中Action跳转(转载)

    windows server 证书的颁发与IIS证书的使用   最近工作业务要是用服务器证书验证,在这里记录下一. 1.添加服务器角色 [证书服务] 2.一路下一步直到证书服务安装完成; 3.选择圈选 ...

  7. java图片处理工具之-ImageMagick+jmagick(二)

    简单的图片处理測试类: public class ImageUtil { static{           System.setProperty("jmagick.systemclassl ...

  8. python 字符编码处理问题总结 彻底击碎乱码!

    Python中常常遇到这种字符编码问题,尤其在处理网页源代码时(特别是爬虫中): UnicodeDecodeError: 'XXX' codec can't decode bytes in posit ...

  9. Java小白手记:WEB项目等

    机缘巧合之下,工作中得以用一下java.我向来对java很感兴趣,想从.NET转到java久矣,机会难得,久旱逢甘霖. 这次主要是跟web项目有关.在此之前,我了解到JAVA分为三大块:j2se.j2 ...

  10. 洛谷P1328==codevs3716 生活大爆炸版石头剪刀布[NOIP 2014 day1 T1]

    P1328 生活大爆炸版石头剪刀布 1.8K通过 2.6K提交 题目提供者2014白永忻 标签模拟NOIp提高组2014 难度普及- 提交该题 讨论 题解 记录 最新讨论 Who can help m ...