int G[1005][1005]; int n, m,k; const int inf = 0x3f3f3f3f; int deep[1005]; int bfs(int s, int t) { queue<int>Q; Q.push(s); memset(deep, 0, sizeof(deep)); deep[s] = 1; while(!Q.empty()) { int u = Q.front(); Q.pop(); for(int i = 0; i <= n + m + 2; i++) { if(G[u][i] == 0) continue; int w = G[u][i]; if(deep[i] == 0 && w > 0) { deep[i] = deep[u] + 1; Q.push(i); } } } if(deep[t] == 0) return 0; return 1; }
int dfs(int s, int dis) { if(s == n + m + 2) return dis; for(int i = 0; i <= n + m + 2; i++) { if(G[s][i] == 0) continue; int w = G[s][i]; if(w > 0 && deep[i] == deep[s] + 1) { int d = dfs(i, min(dis, w)); if(d > 0){ G[s][i] -= d; G[i][s] += d; return d; } } } return 0; } int main() { int num, num1; cin >> n >> m >> k; memset(G, 0, sizeof(G)); for(int i = 1; i <= n; ++i) { cin >> num; G[0][i] = 1; G[n + m + 1][i] = 1; for(int j = 1; j <= num; ++j) { scanf("%d",&num1); G[i][num1 + n] = 1; G[num1 + n][n + m + 2] = 1; } } G[0][n + m + 1] = k; int sum = 0; while(bfs(0, n + m + 2)) { while(int d = dfs(0, inf)) sum += d; } cout << sum << '\n'; }