https://www.luogu.com.cn/problem/P3386
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 5; int match[M], vis[M]; vector<int> f[M]; bool dfs(int now) { for (auto x : f[now]) if (!vis[x]) { vis[x] = 1; if (!match[x] || dfs(match[x])) { match[x] = now; return 1; } } return 0; } void solve() { int n, m, t; cin >> n >> m >> t; while (t--) { int x, y; cin >> x >> y; f[x].push_back(y); } int ans = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) vis[j] = 0; if (dfs(i)) ans++; } cout << ans; } signed main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int t = 1; // cin>>t; while (t--) solve(); return 0; }

