码迷,mamicode.com
首页 > 其他好文 > 详细

poj 3692 Kindergarten,二分图的最大团

时间:2014-09-11 12:36:41      阅读:175      评论:0      收藏:0      [点我收藏+]

标签: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;
}
















poj 3692 Kindergarten,二分图的最大团

标签:style   blog   http   color   io   ar   for   art   sp   

原文地址:http://blog.csdn.net/yew1eb/article/details/39204053

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!