Poj 3692 Kindergarten 二分圖最大獨立點集

題目鏈接


#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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章