1 /**************************************************************
2 Problem: 1711
3 User: Doggu
4 Language: C++
5 Result: Accepted
6 Time:8 ms
7 Memory:2428 kb
8 ****************************************************************/
9
10 #include <cstdio>
11 #include <cstring>
12 #include <algorithm>
13 template<class T>inline void readin(T &res) {
14 static char ch;T flag=1;
15 while((ch=getchar())<‘0‘||ch>‘9‘)if(ch==‘-‘)flag=-1;
16 res=ch-48;while((ch=getchar())>=‘0‘&&ch<=‘9‘)res=(res<<1)+(res<<3)+ch-48;res*=flag;
17 }
18
19 const int N = 1000;
20 const int M = 100000;
21 struct Edge {int v,upre,cap,flow;}g[M];
22 int head[N], ne=-1;
23 inline void adde(int u,int v,int cap) {
24 g[++ne]=(Edge){v,head[u],cap,0};head[u]=ne;
25 g[++ne]=(Edge){u,head[v],0,0};head[v]=ne;
26 }
27
28 #include <queue>
29 std::queue<int> q;
30 int n, f, dr, s, t, d[N], cur[N];
31 bool BFS() {
32 while(!q.empty()) q.pop();
33 memset(d,0,sizeof(d));
34 q.push(s);d[s]=1;
35 while(!q.empty()) {
36 int u=q.front();q.pop();
37 for( int i = head[u]; i != -1; i = g[i].upre ) {
38 int v=g[i].v;
39 if(!d[v]&&g[i].cap>g[i].flow) q.push(v), d[v]=d[u]+1;
40 }
41 }
42 return d[t];
43 }
44 int DFS(int u,int a) {
45 if(u==t||a==0) return a;
46 int flow=0, f;
47 for( int &i = cur[u]; i != -1; i = g[i].upre ) {
48 int v=g[i].v;
49 if(d[v]==d[u]+1&&(f=DFS(v,std::min(a,g[i].cap-g[i].flow)))>0) {
50 flow+=f;a-=f;
51 g[i].flow+=f;g[i^1].flow-=f;
52 if(a==0) break;
53 }
54 }
55 if(flow==0) d[u]=0;
56 return flow;
57 }
58 void maxflow() {
59 int flow=0;
60 while(BFS()) {
61 memcpy(cur,head,sizeof(head));
62 flow+=DFS(s,0x3f3f3f3f);
63 }
64 printf("%d\n",flow);
65 }
66
67 int main() {
68 memset(head,-1,sizeof(head));
69 readin(n);readin(f);readin(dr);s=0;t=f+n*2+dr+1;
70 for( int i = 1; i <= f; i++ ) adde(s,i,1);
71 for( int i = 1; i <= n; i++ ) adde(f+i,f+n+i,1);
72 for( int i = 1; i <= dr; i++ ) adde(f+n*2+i,t,1);
73 for( int i = 1, a, b, c; i <= n; i++ ) {
74 readin(a);readin(b);
75 for( int j = 1; j <= a; j++ ) {
76 readin(c);
77 adde(c,f+i,1);
78 }
79 for( int j = 1; j <= b; j++ ) {
80 readin(c);
81 adde(f+n+i,f+n*2+c,1);
82 }
83 }
84 maxflow();
85 return 0;
86 }
87