Maximum flow and matchings
Today n students came to the New University Cafe. Each of them wants to drink a cup of coffee and to eat one cake (none of them does not agree only on coffee or just a cake - in this case the student leaves). The café serves m kinds of coffees and k kinds of cakes. For each type of coffee and pastry it is known how many cups or servings of this type is available.
In addition, each student has his own taste preferences. It is known for each student what kinds of coffee and cakes he loves. None of the students do not agree to eat or drink something other that he does not like.
The owner of the cafe is thinking: what is the maximum number of students can he serve? And can you find this number?
First line contains integers n, m, k (1 ≤ n, m, k ≤ 500).
Second line contains m integers
Cm (1 ≤
Ci ≤ 500) - the number of available cups of coffee for each type.
Third line contains k integers
Pk (1 ≤
Pi ≤ 500) - the number of available cakes for each type.
Next n lines give the information what kind of coffee likes each student. i-th line (1 ≤ i ≤ n) contains number
Xi, followed by different numbers
AXi - the kinds of coffee that likes i-th student.
Next n lines give the information what kind of cakes likes each student. i-th line (1 ≤ i ≤ n) contains number
Yi, followed by different numbers
BYi - the kinds of cakes that likes i-th student.
Print the maximum number of students that can be served in cafe.
2 3 1 5 1 3 2 3 1 2 3 1 2 1 1 1 1