zoukankan      html  css  js  c++  java
  • poj1422最大独立点集合

    二分图:

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

    #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;
    }
  • 相关阅读:
    redis分布式锁原理
    设置linux源
    linux 设置固定ip 并且解决ping www.baidu.com不通问题
    java内存模型
    Messenger和MVVM中的View Services
    MVVMLight
    MVVMLight
    MvvmLight
    MVVM 事件转命令1
    Mvvm简介
  • 原文地址:https://www.cnblogs.com/yigexigua/p/3890370.html
Copyright © 2011-2022 走看看