bzoj 1191 超级英雄Hero 二分图匹配

题目链接

题意

\(m\)道题(按顺序给出),\(n\)个锦囊,每道题能用两种锦囊解,每个锦囊只能用一次。问最多能按顺序解决掉多少道题。

思路

在题与锦囊间连边,用题去匹配锦囊。

跑匈牙利算法,匹配不上即停。

Code

#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
bool used[maxn];
int a[maxn][maxn], match[maxn], n, m;
typedef long long LL;
int find(int x) {
    for (int i = 0; i < n; ++i) {
        if (!used[i] && a[x][i]) {
            used[i] = true;
            if (!match[i] || find(match[i])) {
                match[i] = x;
                return true;
            }
        }
    }
    return false;
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        a[i][x] = a[i][y] = 1;
    }
    int ans = 0;
    int i = 1;
    for (; i <= m; ++i) {
        memset(used, 0, sizeof(used));
        if (find(i)) ++ans;
        else break;
    }
    printf("%d\n", i-1);
    return 0;
}

转载于:https://www.cnblogs.com/kkkkahlua/p/7666821.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值