二分图匹配 poj 3041

最小点覆盖==最大匹配集

我们在计算的时候,用行来匹配列即可

#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=510;
int G[maxn][maxn];
int vis[maxn];
int match[maxn];
int n,k;
int Found(int x)
{
    for(int j=1;j<=n;j++){
        if(!vis[j]&&G[x][j]){
            vis[j]=1;
            if(!match[j]||Found(match[j])){
                match[j]=x;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        G[u][v]=1;
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        memset(vis,0,sizeof(vis));
        if(Found(i)) ans++;
    }
    printf("%d\n",ans);
    return 0;
}

 

posted @ 2020-07-16 10:04  古比  阅读(111)  评论(0编辑  收藏  举报