POJ 1466 Girls and Boys
来源:互联网 发布:阿里云分布式文件系统 编辑:程序博客网 时间:2024/04/30 16:50
二分图
//============================================================================
// Name : hello.cpp// Author : key
// Version : ∞
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;
#define NUM_INF 0x7FFFFFFF
const int MAXN = 505;
int n;
bool g[MAXN][MAXN];
int xm[MAXN];
int ym[MAXN];
bool chk[MAXN];
bool dfs(int u)
{
int v;
for(v=0;v<n;v++)
{
if(g[u][v] && !chk[v])
{
chk[v] = true;
if(ym[v] == -1 || dfs(ym[v]))
{
ym[v] = u;
xm[u] = v;
return true;
}
}
}
return false;
}
int MaxMatch()
{
int u,ret=0;
memset(xm,-1,sizeof(xm));
memset(ym,-1,sizeof(ym));
for(u=0;u<n;u++)
{
if(xm[u] == -1)
{
memset(chk,false,sizeof(chk));
if(dfs(u))
ret++;
}
}
return ret;
}
int main()
{
int i,u,v,num;
while(scanf("%d",&n)!=EOF)
{
memset(g,false,sizeof(g));
for(i=0;i<n;i++)
{
scanf("%d: (%d) ",&u,&num);
while(num--)
{
scanf("%d",&v);
g[u][v]=true;
}
}
printf("%d\n",n-(MaxMatch()/2));
}
return 0;
}
- POJ 1466 Girls and Boys
- poj 1466 Girls and Boys
- POJ 1466 Girls and Boys
- POJ-1466-Girls and Boys
- poj 1466 Girls and Boys
- POJ 1466 Girls and Boys
- Poj--1466 Girls and Boys
- POJ 1466 Girls and Boys
- poj 1466 Girls and Boys
- poj 1466 Girls and Boys
- POJ 1466 Girls and Boys
- 【POJ】[1466]Girls and Boys
- poj 1466 Girls and Boys
- POJ 1466 Girls and Boys 二分图
- poj 1466 Girls and Boys (最大独立)
- POJ-1466-Girls and Boys 解题报告
- POJ 1466 Girls and Boys 已翻译
- POJ 1466 Girls and Boys (最大独立集Hungary)
- 嵌入式C笔试总结(长期更新)
- 优化资源
- POJ 1018 Communication System
- POJ 1220 NUMBER BASE CONVERSION
- POJ1287 Networking
- POJ 1466 Girls and Boys
- POJ 1496 1850
- gt_opencv_helloworld_img_实现详解(一)
- 关于开通博客的声明
- POJ 1589 Unix ls
- POJ 2075 Tangled in Cables
- 存贮容量计算单位
- OI比赛注意
- view类控件