n,m分别为两边的点数,E为边数。
int e[maxn][maxn]; int n, m; int vis[maxn], match[maxn]; bool dfs(int x) { for (int i = 1; i <= m; i++) { if (e[x][i]) { if (vis[i]) continue; vis[i] = 1; if (!match[i] || dfs(match[i])) { match[i] = x; return true; } } } return false; } int Match() { int cnt = 0; memset(match, 0, sizeof match); for (int i = 1; i <= n; i++) { memset(vis, 0, sizeof vis); if (dfs(i)) cnt++; } return cnt; } int main() { int E; scanf("%d%d%d", &n, &m, &E); for (int i = 1; i <= E; i++) { int x, y; scanf("%d%d", &x, &y); e[x][y] = 1; } printf("%d", Match()); }