Codeforces 1139E(二分图最大匹配)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces 1139E(二分图最大匹配)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
pi只有0~5000且只找最小的沒(méi)出現(xiàn)的,又要找不同club的,考慮二分匹配,左邊pi,右邊ci,一個(gè)匹配一個(gè)。離線倒著加邊即可。
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; }轉(zhuǎn)載于:https://www.cnblogs.com/AlphaWA/p/10676659.html
總結(jié)
以上是生活随笔為你收集整理的Codeforces 1139E(二分图最大匹配)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: live server使用
- 下一篇: 郑州网络推广教你如何筛选到更合适的网站S