qwq,好心人救一下吧。
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;
inline int read()
{
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-') w = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
s = (s << 3) + (s << 1) + (ch ^ 48);
ch = getchar();
}
return s * w;
}
int n, f, d, s, t;
int head[N], ne[N], to[N], w[N], id = 1;
void add(int x, int y, int z)
{
to[++id] = y, ne[id] = head[x], w[id] = z, head[x] = id;
to[++id] = x, ne[id] = head[y], w[id] = 0, head[y] = id;
}
int now[N];
int dis[N];
int q[N], l, r;
void bfs(int s)
{
memset(dis, -1, sizeof dis);
dis[q[l = r = 1] = s] = 0;
while(l <= r)
{
int u = q[l++];
for(int i = head[u]; i; i = ne[i])
{
int v = to[i];
if(w[i] && !~dis[v])
{
q[++r] = v;
dis[v] = dis[u] + 1;
}
}
}
return ;
}
int dfs(int u, int f)
{
if(u == t) return f;
int res = f, t;
for(int &i = now[u]; i; i = ne[i])
{
int v = to[i];
if(w[i] && dis[v] == dis[u] + 1)
{
t = dfs(v, min(res, w[i]));
if(t)
{
w[i] -= t;
w[i ^ 1] += t;
res -= t;
if(!res) break;
}
else dis[v] = 0;
}
}
return f - res;
}
int dinic()
{
int ans = 0, f;
while(1)
{
for(int i = 1; i <= n; i++) now[i] = head[i];
bfs(s);
f = dfs(s, 1e18);
if(!f) return ans;
ans += f;
}
return -1;
}
signed main()
{
n = read(), f = read(), d = read();
t = n + n + f + d + 1;
for(int i = 1; i <= f; i++) add(s, i, 1);
for(int i = 1; i <= n; i++) add(i + f, i + n + f, 1);
for(int i = 1; i <= d; i++) add(i + n + n + f, t, 1);
for(int i = 1; i <= n; i++)
{
int fc = read(), dc = read();
for(int j = 1; j <= fc; j++)
{
int x = read();
add(x, i + f, 1);
}
for(int j = 1; j <= dc; j++)
{
int x = read();
add(n + i + f, n + n + x + f, 1);
}
}
printf("%lld\n", dinic());
return 0;
}