首页 > 其他 > 详细

poj1422最大独立点集合

时间:2014-08-04 17:28:27      阅读:312      评论:0      收藏:0      [点我收藏+]

二分图:

最大独立点集 = 顶点 - 最大匹配

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <iostream>
#include <map>
#include <cstdlib>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include<math.h>
using namespace std;
const int maxn=222;
int Map[maxn][maxn];
int link[maxn];
int used[maxn];
int n;
int dfs(int x)
{
    for(int i=1;i<=n;i++){
        if(!used[i]&&Map[x][i]){
            used[i]=1;
            if(link[i]==-1||dfs(link[i])){
                link[i]=x;return 1;
            }
        }
    }
    return 0;
}

void gao()
{
    memset(link,-1,sizeof(link));
    int ans=0;
    for(int i=1;i<=n;i++){
        memset(used,0,sizeof(used));
        if(dfs(i)) ans++;
    }
    cout<<n-ans<<endl;
}
int main()
{
    int Icase;
    int m;
    scanf("%d",&Icase);
    while(Icase--){
        scanf("%d",&n);
        scanf("%d",&m);
        memset(Map,0,sizeof(Map));
        for(int i=0;i<m;i++){
            int a;int b;
            scanf("%d%d",&a,&b);
            Map[a][b]=1;
        }
        gao();
    }
    return 0;
}

 

poj1422最大独立点集合,布布扣,bubuko.com

poj1422最大独立点集合

原文:http://www.cnblogs.com/yigexigua/p/3890370.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!