poj 3692 (二分图的最大团)
由定理可知:图的最大团=这个图补图的最大独立集。
由于这个图是二分图,独立集可用匈牙利算法求得!!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define LL long long
#define M 205
#define DEBUG puts("It's here!")
#define INF 1<<29
#define CLS(x,v) memset(x,v,sizeof(x))
#define FOR(i,a,n) for(int i=(a);i<=(n);++i)
int graph[M][M];
int n,m;
bool vis[M];
int link[M];
bool DFS(int x)
{
for(int i=1;i<=m;i++)
if(!vis[i]&&graph[x][i]==0)
{
vis[i]=1;
if(link[i]==-1||DFS(link[i]))
{
link[i]=x;return 1;
}
}
return 0;
}
int hungry()
{
int cnt=0;
CLS(link,-1);
for(int i=1;i<=n;i++)
{
CLS(vis,0);
if(DFS(i))cnt++;
}
return cnt;
}
int main()
{
int a,b,k,cnt=1;
while(~scanf("%d%d",&n,&m)&&(n||m))
{
CLS(graph,0);
scanf("%d",&k);
FOR(i,1,k)
{
scanf("%d%d",&a,&b);
graph[a][b]=1;
}
printf("Case %d: ",cnt++);
printf("%d\n",n+m-hungry());
}
return 0;
}