1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4
5 #define maxn 510
6 #define R register
7 #define inf 0x7fffffff
8 #define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
9 int id2[maxn], id3[maxn], tot, num[maxn][maxn];
10 int s, t, ans, deg[maxn << 2];
11 bool req[maxn][maxn];
12 struct Edge {
13 Edge *next, *rev;
14 int to, cap;
15 } *cur[maxn << 2], *last[maxn << 2], e[maxn * maxn << 2], *ecnt = e;
16 inline void link(R int a, R int b, R int w)
17 {
18 *++ecnt = (Edge) {last[a], ecnt + 1, b, w}; last[a] = ecnt;
19 *++ecnt = (Edge) {last[b], ecnt - 1, a, 0}; last[b] = ecnt;
20 }
21 int q[maxn << 2], dep[maxn << 2];
22 inline bool bfs()
23 {
24 memset(dep, -1, (t + 1) << 2);
25 R int head = 0, tail = 1; dep[q[1] = t] = 0;
26 while (head < tail)
27 {
28 R int now = q[++head];
29 for (R Edge *iter = last[now]; iter; iter = iter -> next)
30 if (iter -> rev -> cap && dep[iter -> to] == -1)
31 dep[q[++tail] = iter -> to] = dep[now] + 1;
32 }
33 return dep[s] != -1;
34 }
35 int dfs(R int x, R int f)
36 {
37 if (x == t) return f;
38 R int used = 0;
39 for (R Edge* &iter = cur[x]; iter; iter = iter -> next)
40 if (iter -> cap && dep[iter -> to] + 1 == dep[x])
41 {
42 R int v = dfs(iter -> to, dmin(f - used, iter -> cap));
43 iter -> cap -= v;
44 iter -> rev -> cap += v;
45 used += v;
46 if (f == used) return f;
47 }
48 return used;
49 }
50 void dinic()
51 {
52 while (bfs())
53 {
54 memcpy(cur, last, sizeof last);
55 ans += dfs(s, inf);
56 }
57 }
58 int main()
59 {
60 R int n, m, k; tot = 1; scanf("%d%d%d", &n, &m, &k); link(s, 1, k);
61 for (R int i = 1; i <= m; ++i) id3[i] = ++tot;
62 for (R int i = 1; i <= n; ++i)
63 {
64 R int c; scanf("%d", &c);
65 id2[i] = ++tot;
66 for (R int j = 1; j <= c; ++j)
67 {
68 R int x; scanf("%d", &x);
69 ++num[i][x];
70 }
71 }
72 R int F; scanf("%d", &F);
73 for (R int i = 1; i <= F; ++i)
74 {
75 R int a, b; scanf("%d%d", &a, &b); req[a][b] = 1;
76 }
77 t = ++tot;
78 for (R int i = 1; i <= m; ++i)
79 {
80 R int a; scanf("%d", &a);
81 link(id3[i], t, a);
82 }
83 for (R int i = 1; i <= n; ++i)
84 {
85 R int p, l; scanf("%d%d", &p, &l);
86 link(1, id2[i], p - l); deg[1] += l; deg[id2[i]] -= l;
87 }
88 for (R int i = 1; i <= n; ++i)
89 for (R int j = 1; j <= m; ++j)
90 if (req[i][j])
91 {
92 link(id2[i], id3[j], num[i][j] - 1);
93 ++deg[id2[i]]; --deg[id3[j]];
94 }
95 else if (num[i][j]) link(id2[i], id3[j], num[i][j]);
96 R int os = s, ot = t; link(t, s, inf);
97 s = ++tot; t = ++tot;
98 for (R int i = 1; i <= tot; ++i) deg[i] > 0 ? link(i, t, deg[i]) : link(s, i, -deg[i]);
99 dinic();
100 s = os; t = ot; ans = 0;
101 dinic();
102 printf("%d\n", ans);
103 return 0;
104 }