POJ 3692 最大团

最大团=补图最大独立集

when 补图是二分图时, 最大团=补图顶点数-最大匹配

//
//  main.cpp
//  poj3692
//
//  Created by Fangpin on 15/5/29.
//  Copyright (c) 2015年 FangPin. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN=205;
bool vis[MAXN];
int link[MAXN];
int B,G;
int g[MAXN][MAXN];

bool dfs(int x){
    for(int i=1;i<=B;++i){
        if(g[x][i] && !vis[i]){
            vis[i]=true;
            if(link[i]==-1 || dfs(link[i])){
                link[i]=x;
                return true;
            }
        }
    }
    return false;
}

int hungry(){
    int ans=0;
    memset(link,-1,sizeof(link));
    for(int i=1;i<=G;++i){
        memset(vis,false,sizeof(vis));
        if(dfs(i)) ++ans;
    }
    return ans;
}

int main(int argc, const char * argv[]) {
    for(int ca=1;;++ca){
        int m;
        scanf("%d%d%d",&G,&B,&m);
        if(G+B+m==0) break;
        memset(g,1,sizeof(g));
        for(int i=0;i<m;++i){
            int x,y;
            scanf("%d%d",&x,&y);
            g[x][y]=0;
        }
        cout<<"Case "<<ca<<": "<<G+B-hungry()<<endl;
    }
    return 0;
}
时间: 2024-11-06 14:13:18

POJ 3692 最大团的相关文章

POJ 3692:Kindergarten(最大团)

Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4920   Accepted: 2399 Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some

poj 3692 Kindergarten (最大团模板题)

题目链接:http://poj.org/problem?id=3692 Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5156   Accepted: 2512 Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know e

(最大团) poj 3692

L - Kindergarten Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3692 Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each ot

poj 3692 二分图最大匹配

题意: 已知班级有g个女孩和b个男孩,所有女生之间都相互认识,所有男生之间也相互认识,给出m对关系表示哪个女孩与哪个男孩认识.现在要选择一些学生来组成一个团,使得里面所有人都互相认识,求此团最大人数. 限制: 1 <= g,b <= 200; 0 <= m <= b*g 思路: 求最大团. 最大独立集=|V|-最大匹配 最大团=补图的最大独立集 由题意可得,互相不认识的连边,构成一个二分图,ans=|V|-最大匹配,匈牙利算法. /*poj 3692 题意: 已知班级有g个女孩和b

POJ 3692 Kindergarten【最大点独立集】

大意: 有n个boy  m个girle   boy之间相互了解  girle之间相互了解 又告诉你一些boy和girle之间相互了解的关系 问最多选出多少人使其相互之间相互了解 分析: 左集合boy  右girle 若boy与girle相互不了解则建一条边,这样,有边相连的便是不相互了解的 那么最大点独立便是选取一些点使其相互之间没有边相连也就是相互了解的 note: 由于左右集合不相等所以选取nm中的较大的作为点的个数 最后结果为2 * max(n, m) - 最大匹配 代码: 1 #incl

poj 3692 Kindergarten (最大独立集)

Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4903   Accepted: 2387 Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some

POJ 3692 Kindergarten (二分图 最大团)

Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5660   Accepted: 2756 Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some

POJ 3692 Kindergarten(最大团问题)

题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pi

poj 3692 Kindergarten,二分图的最大团

最大独立集 = V - 最小顶点覆盖 二分图的最小顶点覆盖数 = 最大匹配数 最大团 = 补图的最大独立集 #include <cstdio> #include <cstring> #include <algorithm> #include <stack> #include <vector> #include <queue> using namespace std; const int maxn = 200 + 10; int n,