题意:
在一个幼儿园中,所有的女孩互相认识..所有的男孩互相认识..有些女孩和男孩认识..现在要选出一些人来搞活动.要求他们都互相认识..问最多能选出多少人..
题解:
对一个无向图来说,独立点集就是选出若干个点使得他们之间两两都不可达...二分图的最大独立点集就是选出最多的点,使它们两两间都没有边...解法是用两侧点的总数减去二分图最大匹配数....对于本题..正着求麻烦..把边反过来建..不认识的的建边..求出的最大独立点集就是互相都认识的了...
Program:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<string.h>
#include<queue>
#define ll long long
#define esp 1e-5
#define MAXN 202
#define MAXM 50000000
#define oo 100000007
using namespace std;
int G,B,match[MAXN];
bool used[MAXN],arc[MAXN][MAXN];
bool dfs(int x)
{
int i,j;
for (i=1;i<=B;i++)
if (arc[x][i] && !used[i])
{
used[i]=true;
if (!match[i] || dfs(match[i]))
{
match[i]=x;
return true;
}
}
return false;
}
int getmax()
{
int i,ans=0;
memset(match,0,sizeof(match));
for (i=1;i<=G;i++)
{
memset(used,false,sizeof(used));
ans+=dfs(i);
}
return ans;
}
int main()
{
int x,y,M,cases=0;
while (~scanf("%d%d%d",&G,&B,&M) && (G || B))
{
memset(arc,true,sizeof(arc));
while (M--)
{
scanf("%d%d",&x,&y);
arc[x][y]=false;
}
printf("Case %d: %d\n",++cases,G+B-getmax());
}
return 0;
}