Bipartite graph maximum matching problem
Now an array of standard cow in cattle byre is the date of cattle
Each looking to be emptied vis array
If there are two possible cases
1. The cowshed no cattle
2. The cattle byre where you can go to another bullpen
According to this recursive
Code:
#include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N = 250; int cow[N], m, ans, n, p, q; bool mp[N][N], vis[N]; int read() { int s = 0, w = 1; char ch = getchar(); while(!isdigit(ch)) {if(ch == '-') w = -1; ch = getchar();} while(isdigit(ch)) {s = s * 10 + ch - '0'; ch = getchar();} return s * w; } bool find(int x) { for(int i = 1; i <= m; i++) { if(mp[x][i] && !vis[i]) { vis[i] = 1; if(!cow[i] || find(cow[i])) {cow[i] = x; return 1;} } } return 0; } int main() { n = read(), m = read(); for(int i = 1; i <= n; i++) { p = read(); for(int j = 1; j <= p; j++) q = read(), mp[i][q] = 1; } for(int i = 1; i <= n; i++) { memset(vis, 0, sizeof(vis)); if(find(i)) ans++; } printf("%d\n", ans); return 0; }
Thank you for watching, I wish good health!