https://www.luogu.org/problemnew/show/P3386#sub
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 6 int match[1005], lt[1005][1005], n, m, e, vis[1005]; 7 8 inline bool dfs(int u){ 9 for(int i = 1; i <= m; ++i){ 10 if(!vis[i] && lt[u][i]){ 11 vis[i] = 1; 12 if (!match[i] || dfs(match[i])){ 13 match[i] = u; 14 return true; 15 } 16 } 17 } 18 return false; 19 } 20 21 int main(void){ 22 int ans = 0; 23 scanf("%d%d%d", &n, &m, &e); 24 for(int u, v, i = 1; i <= e; ++i){ 25 scanf("%d%d", &u, &v); if (u <= n && v <= m){lt[u][v] = 1;} 26 } 27 for(int i = 1; i <= n; ++i){ 28 memset(vis, 0, sizeof(vis)); 29 if (dfs(i)) ans++; 30 } 31 printf("%d", ans); 32 33 return 0; 34 }