poj 3692 Kindergarten
http://poj.org/problem?id=3692
挑选最多的互相认识的小朋友
补图的最大独立集
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std;
int g, b, k, a[403][403], match[403], vis[403] ;
char map[42][12];
bool find(int u){
int i;
for( i=1; i<=g+b; i++){
if(a[u][i]==0 && !vis[i]){
vis[i]=1;
if( match[i]==-1 || find(match[i])){
match[i]=u;
return true;
}
}
}
return false;
}
int hungary(){
int i ,ans=0;
for(i=1; i<=g+b; i++){
memset(vis, 0, sizeof(vis));
if(find(i))
ans++;
}//cout<<ans<<endl;
// printf("%d\n", sum-ans/2);
return g+b-ans/2;
}
void init(){
memset(a, 0, sizeof(a));
memset(match, -1, sizeof(match));
int i, j, x, y;
for( i=0 ; i<k; i++){
scanf("%d%d", &x, &y);
a[x][y+g]=1;
a[y+g][x]=1;
}
for(i=1 ; i<=g; i++){
for(j=1; j<=g; j++){
a[i][j]=1;
a[j][i]=1;
}
}
for(i=g+1; i<=b+g; i++){
for(j=g+1; j<=b+g; j++){
a[i][j]=1;
a[j][i]=1;
}
}
}
int main(){
// freopen("1.txt", "r", stdin);
int t=1;
while(scanf("%d%d%d", &g, &b, &k)&&!(g==0 && b==0 && k==0)){
init();
// hungary();
printf("Case %d: %d\n", t++, hungary());
}
return 0;
}