POJ 1274 The Perfect Stall 二分匹配模板
来源:互联网 发布:酒店网络设计 编辑:程序博客网 时间:2024/06/16 19:05
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
vector<int> G[405];
int match[405],used[405];
int n,m;
void add_edge(int u,int v)
{
G[u].push_back(v);
G[v].push_back(u);
}
bool dfs(int u)
{
used[u]=1;
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i];
int w=match[v];
if(w<0||!used[w]&&dfs(w))
{
match[u]=v;
match[v]=u;
return true;
}
}
return false;
}
void bipartite_match()
{
memset(match,-1,sizeof(match));
int res=0;
for(int i=1;i<=n;i++)
if(match[i]<0)
{
memset(used,0,sizeof(used));
if(dfs(i)) res++;
}
printf("%d\n",res);
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
int u,v,num;
for(int i=1;i<=n+m;i++)
G[i].clear();
for(int u=1;u<=n;u++)
{
scanf("%d",&num);
for(int j=0;j<num;j++)
{
scanf("%d",&v);
add_edge(u,v+n);
}
}
bipartite_match();
}
return 0;
}
- poj 1274The Perfect Stall 二分匹配模板水题
- POJ-1274The Perfect Stall,二分匹配裸模板题
- POJ 1274 The Perfect Stall 二分匹配模板
- 【POJ】1274 The Perfect Stall 二分匹配
- Poj 1274 The Perfect Stall【二分匹配】
- poj 1274 The Perfect Stall 【二分匹配裸题】【练模板】
- POJ-1274-The Perfect Stall【二分图最大匹配】【模板题】
- POJ-1274 The Perfect Stall (二分图最大匹配模板题)
- POJ 1274 The Perfect Stall(最大二分匹配)
- POJ 1274 The Perfect Stall 二分图最大匹配
- 二分图匹配(简单题)POJ 1274 The Perfect Stall
- 二分图最大基数匹配 POJ 1274 The Perfect Stall
- POJ 1274 The Perfect Stall(二分图最大匹配)
- 【二分图+最大匹配】北大 poj 1274 The Perfect Stall
- poj 匈牙利二分匹配 1274 The Perfect Stall
- POJ 1274 The Perfect Stall(二分匹配)
- POJ 1274 The Perfect Stall 【二分图匹配】
- POJ 1274 The Perfect Stall(二分匹配)- from lanshui_Yang
- CF 551B 暴力+字符串
- CF 551c 二分搜索+思维题
- UVA 10054
- cf 550A 字符串统计
- CF 字符串+数论
- POJ 1274 The Perfect Stall 二分匹配模板
- CF Mike and Fax 字符串组成
- POJ 3250 单调栈模板
- POJ 1486 Sorting Slides 二分匹配变形 完全匹配
- POJ 2559 单调栈模板
- POJ 2082 Terrible Sets 单调栈基础
- POJ 3494 Largest Submatrix of All 1’s 二维栈 好题
- CF D. Mike and Feet 单调栈的运用
- CfRound #342 (Div. 2) Guest From the Past 贪心思维题