AcWing 861. 二分图的最大匹配
原题链接
简单
作者:
郡呈
,
2019-08-12 15:59:16
,
所有人可见
,
阅读 1148
#include <iostream>
#include <cstring>
using namespace std;
const int N = 510, M = 2e5+10;
int n1, n2, m, u, v, ans = 0;
int h[N], e[M], ne[M], idx;
int match[N];
bool st[N];
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
bool find(int x) {
for(int i = h[x]; i != -1; i = ne[i]) {
int j = e[i];
if(!st[j]) {
st[j] = true;
if(match[j] == 0 || find(match[j])) {
match[j] = x;
return true;
}
}
}
return false;
}
int main() {
cin >> n1 >> n2 >> m;
memset(h, -1, sizeof h);
while(m--) {
cin >> u >> v;
add(u, v);
}
for(int i = 1; i <= n1; i++) {
memset(st, false, sizeof st);
if(find(i)) ans++;
}
cout << ans << endl;
return 0;
}
小笔误://代表妹子对应的 “女朋友” 应该是♂朋友
哈哈哈哈不要在意这些细节
很生动 的讲解……^_^
https://blog.csdn.net/Dark_Scope/article/details/8880547 看博客和大佬的讲解写的hhh