Jamie's Contact Groups POJ - 2289
来源:互联网 发布:设计师笔记本2017知乎 编辑:程序博客网 时间:2024/06/02 00:51
题目连接点这里
二分图多重匹配模版题,
二分答案后,跑匈牙利就可以了
#include<iostream>#include<stdio.h>#include<queue>#include<algorithm>#include<string.h>#define MX 2222#define INF 0x3f3f3f3f#define mem(x,y) memset(x,y,sizeof(x))#define FIN freopen("input.txt","r",stdin)using namespace std;int n,m;int head[MX],rear;int mid;struct{ int to,nxt;} edge[1111*MX];void edge_init(){ mem(head,-1); rear=0;}void edge_add(int a,int b){ edge[rear].to=b; edge[rear].nxt=head[a]; head[a]=rear++;}bool vis[MX];int match[MX][1111];int mcnt[MX];bool hungarian_dfs(int u){ for(int i=head[u]; ~i; i=edge[i].nxt) { int v=edge[i].to; if(vis[v]) continue; vis[v]=1; if(mcnt[v]<mid) { match[v][++mcnt[v]]=u; return 1; } for(int j=1; j<=mid; j++) if(hungarian_dfs(match[v][j])) { match[v][j]=u; return 1; } } return 0;}int hungarian(){ mem(mcnt,0); int ret=0; for(int i=1; i<=n; i++) { mem(vis,0); if(hungarian_dfs(i)==0) return 0; } return 1;}int erfeng(int l,int r){ while(l<r) { mid=((l+r)>>1); if(hungarian()) r=mid; else l=mid+1; } return l;}bool lof;bool Int(int &a){ if(lof) return lof=0; char c; for(c=getchar(); c<'0'||c>'9'; c=getchar())if(c=='\n')return 0; a=c-'0'; for(c=getchar(); c>='0'&&c<='9'; c=getchar())a=a*10+c-'0'; lof=c=='\n'; return 1;}int main(){ FIN; while(scanf("%d%d",&n,&m)&&n) { edge_init(); char s[1111]; for(int i=1; i<=n; i++) { scanf("%s",s); lof=0; int x; while(Int(x)) edge_add(i,x+n+1),edge_add(x+n+1,i); } printf("%d\n",erfeng(1,n)); } return 0;}
0 0
- POJ 2289 Jamie's Contact Groups
- POJ-2289-Jamie's Contact Groups
- POJ 2289 Jamie's Contact Groups
- Jamie's Contact Groups POJ - 2289
- POJ 2289 Jamie's Contact Groups 多重匹配+二分
- POJ 2289 Jamie's Contact Groups (二分+dinic)
- poj 2289 Jamie's Contact Groups 二分图多重匹配
- poj 2289 Jamie's Contact Groups(二分+多重匹配)
- POJ 2289 - Jamie's Contact Groups 二分+最大流
- POJ 2289 Jamie's Contact Groups 二分+最大匹配
- Poj-2289 Jamie's Contact Groups 多重二分图匹配
- POJ 2289 Jamie's Contact Groups 二分图多重匹配
- POJ 2289 Jamie's Contact Groups(二分+最大流)
- poj 2289 Jamie's Contact Groups 二分+网络流
- poj 2289 Jamie's Contact Groups (二分图多重匹配)
- poj 2289 Jamie's Contact Groups 【二分 + 最大流】
- poj 2289 Jamie's Contact Groups【二分 + 最大流】
- poj 2289 Jamie's Contact Groups 二分图多重匹配
- 在CocosStudio中自建的文件中没有锚点的选项
- Java多态性理解
- 快速集成APP注册页面免费获取短信验证码功能
- 算法提高 图形输出
- Speaker Recognition Evaluation 2012
- Jamie's Contact Groups POJ - 2289
- MATLAB中带有符号变量的阶乘、累加函数的表达与求解
- 百度地图自定义标注物+自动定位
- 【Hibernate】一对一关联映射
- Latex调整行间距
- Ubuntu14.04安装mlpy(机器学习库)---python
- 精选30道Java笔试题解答
- 高校云平台(八):分析代码依赖关系
- Qt学习1之初建小工程