标签:style blog http color io ar for art sp
最大独立集 = V - 最小顶点覆盖
最大团 = 补图的最大独立集
#include <cstdio> #include <cstring> #include <algorithm> #include <stack> #include <vector> #include <queue> using namespace std; const int maxn = 200 + 10; int n, m, s; int map[maxn][maxn], vis[maxn], link[maxn]; int dfs(int u) { for(int i=1; i<=m; ++i) { if(vis[i]==0 && map[u][i]) { vis[i] = 1; if(link[i]==-1||dfs(link[i])) { link[i] = u; return 1; } } } return 0; } int Max_Match() { int res = 0; memset(link, -1, sizeof link ); for(int i=1; i<=n; ++i) { memset(vis, 0, sizeof vis ); if(dfs(i)) res++; } return res; } int main() { int x, y, t = 1; while(~scanf("%d%d%d", &n, &m, &s)) { if(n==0&&m==0&&s==0) break; memset(map, 1, sizeof map ); for(int i=0; i<s; ++i) { scanf("%d%d", &x, &y); map[x][y] = 0; } printf("Case %d: %d\n",t++, n+m-Max_Match()); } return 0; }
标签:style blog http color io ar for art sp
原文地址:http://blog.csdn.net/yew1eb/article/details/39204053