顺便记下kuangbin巨巨的HK
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn = 3005;
vector<int>G[maxn];
int un;
int mx[maxn], my[maxn];
int dx[maxn], dy[maxn];
bool use[maxn];
int dis;
bool searchp() {
queue<int>Q;
dis = inf;
memset(dx, -1, sizeof(dx));
memset(dy, -1, sizeof(dy));
for (int s = 0; s < un; s++)
if (mx[s] == -1) {
Q.push(s);
dx[s] = 0;
}
while (!Q.empty()) {
int u = Q.front();
Q.pop();
if (dx[u] > dis)break;
int sz = G[u].size();
for (int s = 0; s < sz; s++) {
int v = G[u][s];
if (dy[v] == -1) {
dy[v] = dx[u] + 1;
if (my[v] == -1)dis = dy[v];
else {
dx[my[v]] = dy[v] + 1;
Q.push(my[v]);
}
}
}
}
return dis != inf;
}
bool dfs(int u) {
int sz = G[u].size();
for (int s = 0; s < sz; s++) {
int v = G[u][s];
if (!use[v] && dy[v] == dx[u] + 1) {
use[v] = 1;
if (my[v] != -1 && dy[v] == dis)continue;
if (my[v] == -1 || dfs(my[v])) {
my[v] = u;
mx[u] = v;
return 1;
}
}
}
return 0;
}
int maxmatch()
{
int ans = 0;
memset(mx, -1, sizeof(mx));
memset(my, -1, sizeof(my));
while (searchp()) {
memset(use, 0, sizeof(use));
for (int s = 0; s < un; s++) {
if(mx[s] == -1 && dfs(s))
ans++;
}
}
return ans;
}