hdu 1054 最小点覆盖

二分图中,最小点覆盖=最大匹配

这个是二分图。求出最大匹配/2, 因为每个匹配我们计算了两次

//by dezhonger
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <deque>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <stack>
using namespace std;

#define rep(i, a, b) for( i = (a); i <= (b); i++)
#define reps(i, a, b) for( i = (a); i < (b); i++)
#define pb push_back
#define ps push
#define mp make_pair
#define CLR(x,t) memset(x,t,sizeof x)
#define LEN(X) strlen(X)
#define F first
#define S second
#define Debug(x) cout<<#x<<"="<<x<<endl;


const double euler_r = 0.57721566490153286060651209;
const double pi = 3.141592653589793238462643383279;
const double E = 2.7182818284590452353602874713526;
const int inf=~0U>>1;
const int MOD = int(1e9) + 7;
const double EPS=1e-6;
const int mod = int(1e9) + 7;
typedef long long ll;
typedef long long LL;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
const int N = 2000;
vector<int> g[N+10];
int match[N+10];
bool visit[N+10];

int read()
{
    int x = 0;
    char ch = ' ';
    while(ch < '0' || ch > '9') ch = getchar();
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    return x;
}
int find(int x)
{
    for(int i = 0; i < g[x].size(); i++)
    {
        int k = g[x][i];
        if(!visit[k])
        {
            visit[k] = true;
            if(match[k] == -1 || find(match[k]))
            {
                match[k] = x;
                return true;
            }
        }
    }
    return false;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ios_base::sync_with_stdio(0);
    int n, m, u, v, ans;
    while(scanf("%d",&n)!=-1)
    {

        ans = 0;
        CLR(match, -1);
        for(int i = 0; i < n; i++) g[i].clear();
        for(int i = 0; i < n; i++)
        {

            u = read();
//            cout <<  u << " ";
            m = read();
//            cout << m << endl;
            for(int j = 1; j <= m ;j++)
            {
                v = read();
                g[u].pb(v);
                g[v].pb(u);
            }
        }

        for(int i = 0; i < n; i++)
        {
            CLR(visit, 0);
            ans += find(i);
        }
        printf("%d\n", ans/2);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值