您的位置:首页 > 其它

Poj 3692 Kindergarten 二分图最大独立点集

2014-07-17 22:08 344 查看
题目链接

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 205;
const int Mod = 1000000007;
const double inf = 1<<30;
int G,B,m;
struct node
{
int ld,rd;
}point[maxn];
int map[maxn][maxn],cx[maxn],cy[maxn];
bool vis[maxn];
bool FindPath( int u )
{
for( int i = 1; i <= B; i ++ )
{
if( !vis[i] && !map[u][i] )
{
vis[i] = 1;
if( cy[i] == -1 || FindPath( cy[i] ) )
{
cy[i] = u;
cx[u] = i;
return true;
}
}
}
return false;
}
int MaxMatch()
{
int ans = 0;
memset( cx,-1,sizeof(cx) );
memset( cy,-1,sizeof(cy) );
for( int i = 1; i <= G; i ++ )
{
if( cx[i] == -1 )
{
memset( vis,0,sizeof(vis) );
ans += FindPath( i );
}
}
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt","r",stdin);
#endif
int a,b,C = 1;
while( scanf("%d%d%d",&G,&B,&m) != EOF,(G||B||m) )
{
memset( map,0,sizeof(map) );
for( int i = 0; i < m; i ++ ){
scanf("%d%d",&a,&b);
map[a][b] = 1;
}
printf("Case %d: %d\n",C++,G+B - MaxMatch());
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: