Codeforces 1139E(二分图最大匹配)

pi只有0~5000且只找最小的没出现的,又要找不同club的,考虑二分匹配,左边pi,右边ci,一个匹配一个。离线倒着加边即可。

const int maxn = 5e3 + 5;
int m, n, d, now;
int P[maxn], C[maxn], K[maxn];
int match[maxn], ans[maxn];
bool mark[maxn], used[maxn];
vector<int> G[maxn];

bool dfs(int cur) {
    if (used[cur])  return false;
    used[cur] = 1;
    for (auto to : G[cur]) {
        if (match[to] == -1 || dfs(match[to])) {
            match[to] = cur;
            return true;
        }
    }
    return false;
}

int main() {
    read(m), read(n);
    rep(i, 1, m)    read(P[i]);
    rep(i, 1, m)    read(C[i]);
    read(d);
    rep(i, 1, d) {
        read(K[i]);
        mark[K[i]] = true;
    }
    rep(i, 1, m) {
        if (!mark[i]) {
            G[P[i]].push_back(C[i]);
        }
    }

    init(match, -1);
    irep(i, d, 1) {
        init(used, 0);
        while (dfs(now)) {
            now++;
            init(used, 0);
        }

        ans[i] = now;
        int t = K[i];
        G[P[t]].push_back(C[t]);
    }

    rep(i, 1, d)    writeln(ans[i]);
    return 0;
}

转载于:https://www.cnblogs.com/AlphaWA/p/10676659.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值