注意POJ数组越界可能返回TLE!!!

网络流的maxn大小要注意

其他没什么了 裸二分答案+isap乱搞

不过复杂度没搞懂 V=1e3 E = 1e5 那ISAP的O(V^2E)怎么算都不行啊

 /*--------------------------------------------------------------------------------------*/

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
#define LL long long
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
/*--------------------------------------------------------------------------------------*/
using namespace std; int N,M,T;
const int maxn = ;
const int maxm = ;
//map<int ,string > mp;
vector <int> save[maxn]; struct Edge{
int to,next,cap,flow;
}edge[maxm]; int head[maxn],tot;
int uN = ;
int gap[maxn],dep[maxn],pre[maxn],cur[maxn]; void init()
{
tot = ;
memset(head,-,sizeof head);
} void add_edge(int u,int v,int w,int rw = )
{
//printf("%d->%d %d\n",u,v,w);
edge[tot].to = v;edge[tot].cap = w;edge[tot].next = head[u];
edge[tot].flow = ;head[u] = tot++;
edge[tot].to = u;edge[tot].cap = rw;edge[tot].next = head[v];
edge[tot].flow = ;head[v] = tot++;
}
int Q[maxn];
void BFS(int st,int ed)
{
memset(dep,-,sizeof dep);
memset(gap,,sizeof gap);
gap[] = ;
int front = ,rear = ;
dep[ed] = ;
Q[rear++] = ed;
while(front != rear)
{
int u = Q[front++];
for(int i=head[u];~i;i=edge[i].next)
{
int v = edge[i].to;
if(dep[v] != -) continue;
Q[rear++] = v;
dep[v] = dep[u] + ;
gap[dep[v]] ++;
}
}
}
int S[maxn]; int sap(int st,int ed)
{
BFS(st,ed);
memcpy(cur,head,sizeof head);
int top = ;
int u = st; int ans = ;
while(dep[st] < uN)
{
if(u == ed)
{
int Min = INF;
int inser;
for(int i=;i<top;i++)
{
if(Min > edge[S[i]].cap - edge[S[i] ].flow)
{
Min = edge[S[i]].cap - edge[S[i]].flow;
inser=i;
}
}
for(int i=;i<top;i++)
{
edge[S[i]].flow += Min;
edge[S[i]^].flow -= Min;
}
ans += Min;
top = inser;
u = edge[S[top]^].to;
continue;
}
bool flag = false;
int v;
for(int i=cur[u];~i;i=edge[i].next)
{
v = edge[i].to;
if(edge[i].cap - edge[i].flow && dep[v]+ == dep[u])
{
flag = true;
cur[u] = i;
break;
}
}
if(flag)
{
S[top++] = cur[u];
u = v;
continue;
}
int Min = uN;
for(int i=head[u];~i;i=edge[i].next)
{
if(edge[i].cap - edge[i].flow && dep[edge[i].to] < Min)
{
Min = dep[edge[i].to];
cur[u] = i;
}
}
gap[dep[u]] --;
if(!gap[dep[u]]) return ans;
dep[u] = Min + ;
gap[dep[u] ]++;
if(u != st) u = edge[S[--top]^].to;
}
return ans;
} int check(int mid)
{
uN = N+M+;
init();
for(int i=;i<N;i++)
{
add_edge(N+M,i,);
for(int j=;j<save[i].size();j++)
{
add_edge(i,save[i][j]+N,);
}
}
for(int i=;i<M;i++)
{
add_edge(N+i,N+M+,mid);
} int res = sap(N+M,N+M+);
//printf("mid:%d res:%d\n",mid,res);
if(res == N) return true;
else return false;
} int solve()
{
int L = ,R = *N,mid;
while(L <= R)
{
mid = (L+R)>>;
if(check(mid)) R = mid-;
else L = mid+;
}
//printf("%d %d\n",L,R);
return L;
} int main()
{
while(scanf("%d%d",&N,&M) && N+M)
{
char s[];
//mp.clear();
for(int i=;i<maxn;i++) save[i].clear();
for(int i=;i<N;i++)
{
scanf("%s",s);
char c = getchar();
if(c != ' ') continue;
int num = -;
while((c = getchar()) && c !='\n')
{
if(isdigit(c))
{
if(num == -) num = ;
num *= ;num += c-'';
}
else if(c == ' ')
{
save[i].push_back(num);
num = -;
}
}
if(num != -) save[i].push_back(num);
}
if(M == || N == ) printf("0\n");
else printf("%d\n",solve());
}
}

POJ2289-Jamie's Contact Groups-二分图多重匹配-ISAP的更多相关文章

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

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

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

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

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

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

  4. POJ 2289 Jamie's Contact Groups(多重匹配+二分)

    题意: Jamie有很多联系人,但是很不方便管理,他想把这些联系人分成组,已知这些联系人可以被分到哪个组中去,而且要求每个组的联系人上限最小,即有一整数k,使每个组的联系人数都不大于k,问这个k最小是 ...

  5. HDU 1669 Jamie's Contact Groups(多重匹配+二分枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1669 题目大意: 给你各个人可以属于的组,把这些人分组,使这些组中人数最多的组人数最少,并输出这个人数 ...

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

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

  7. Jamie's Contact Groups---hdu1669--poj2289(多重匹配+二分)

    题目链接 题意:Jamie有很多联系人,但是很不方便管理,他想把这些联系人分成组,已知这些联系人可以被分到哪个组中去,而且要求每个组的联系人上限最小,即有一整数k,使每个组的联系人数都不大于k,问这个 ...

  8. poj2289 Jamie's Contact Groups

    思路: 二分+最大流.实现: #include <stdio.h> #include <stdlib.h> #include <limits.h> #include ...

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

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

随机推荐

  1. 介绍一种css水平垂直居中的方法(非常好用!)

    这次介绍一下一个水平垂直居中的css方法,这个方法可以说是百试百灵,废话不多说,直接附上代码: html,body{ width:100%; height:100%; } 你需要居中的元素{ posi ...

  2. [QualityCenter]设置工作流脚本-新建缺陷时字段自动生成

    需求:新建缺陷时,自动生成缺陷状态.检查者和检查日期的值. 在脚本编辑器找到Defects_Bug_New函数,然后填写以下代码: Sub Defects_Bug_New    On Error Re ...

  3. 2.NopCommerce中文语言包

    由于NopCommerce是纯英语环境,给英语不好的管理人员带来诸多不便. NopCommerce支持多语言环境,所以我们只要安装中文语言包,让NopCommerce支持后台中文操作环境. 首先先下载 ...

  4. jquery实现整屏翻屏效果:jquery.mousewheel(一)

    实现整屏上下翻效果:需加载的js <script type="text/javascript" src="js/jquery-1.8.3.min.js"& ...

  5. sql 入门经典(第五版) Ryan Stephens 学习笔记 第五部分: 性能调整

    第十六章: 利用索引改善性能 1. create index 单字段索引:  create index index_name on table_name (column_name);唯一索引:     ...

  6. 第22章 DLL注入和API拦截(2)

    22.4 使用远程线程来注入DLL 22.4.1 概述 (1)远程线程注入是指一个进程在另一个进程中创建线程,然后载入我们编写的DLL,并执行该DLL代码的技术.其基本思路是通过CreateRemot ...

  7. 改造二叉树 (长乐一中模拟赛day2T1)

    1.改造二叉树 [题目描述] 小Y在学树论时看到了有关二叉树的介绍:在计算机科学中,二叉树是每个结点最多有两个子结点的有序树.通常子结点被称作“左孩子”和“右孩子”.二叉树被用作二叉搜索树和二叉堆.随 ...

  8. Windows系统安装Oracle 11g数据库

    一.下载 http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html以下两网址来源此官方下载页 ...

  9. mongoVUE1.5.3 破解方法

    MongoVUE是个免费软件,但超过15天后功能受限.可以通过删除以下注册表项来解除限制: [HKEY_CURRENT_USER\Software\Classes\CLSID\{B1159E65-82 ...

  10. 用SqlParameter 给SQL传递参数

    1.数据访问层 using的用法: 01.可以using System;导命名控空间 02.using 的语法结构 using(变量类型  变量名 =new 变量类型()) { } 案例: 03.us ...