AT_past202209_f 薬剤師
Description
We have $ N $ kinds of drugs numbered $ 1 $ to $ N $ .
The efficiency of a drug is represented by an integer from $ 1 $ to $ 100 $ ; the greater, the more efficient. The efficiency of Drug $ i $ is $ A_i $ . (All $ A_i $ are distinct.)
The drugs also contain allergens (substances that cause allergic reactions). Allergens are represented by integers from $ 1 $ to $ 2 \times 10^5 $ , and Drug $ i $ contains $ C_i $ allergens $ X_{i,1}, X_{i,2}, \dots, X_{i,C_i} $ .
You are given $ Q $ queries, which should be processed according to the instruction. The $ p $ -th query is the following:
> Person $ p $ has allergies to $ D_p $ allergens $ Y_{p,1}, Y_{p,2}, \dots, Y_{p,D_p} $ , and may not be given a drug containing one or more of those allergens.
> Consider giving Person $ p $ one of the drugs from Drug $ 1 $ to Drug $ N $ . Print the number representing the most efficient drug that may be given to Person $ p $ . If no drug may be given, print $ -1 $ .
Input Format
Input is given from Standard Input in the following format:
> $ N $ $ A_1 $ $ A_2 $ $ \dots $ $ A_N $ $ C_1 $ $ X_{1,1} $ $ X_{1,2} $ $ \dots $ $ X_{1,C_1} $ $ C_2 $ $ X_{2,1} $ $ X_{2,2} $ $ \dots $ $ X_{2,C_2} $ $ \vdots $ $ C_N $ $ X_{N,1} $ $ X_{N,2} $ $ \dots $ $ X_{N,C_N} $ $ Q $ $ D_1 $ $ Y_{1,1} $ $ Y_{1,2} $ $ \dots $ $ Y_{1,D_1} $ $ D_2 $ $ Y_{2,1} $ $ Y_{2,2} $ $ \dots $ $ Y_{2,D_2} $ $ \vdots $ $ D_Q $ $ Y_{Q,1} $ $ Y_{Q,2} $ $ \dots $ $ Y_{Q,D_Q} $
Output Format
Print $ Q $ lines. The $ i $ -th line should contain the answer to the $ i $ -th query.
Explanation/Hint
### Sample Explanation 1
Here is a summary of information about the drugs and queries.
- Drug $ 1 $ has an efficiency of $ 10 $ and contains Allergens $ 1 $ , $ 2 $ , and $ 3 $ .
- Drug $ 2 $ has an efficiency of $ 9 $ and contains Allergen $ 1 $ .
- Drug $ 3 $ has an efficiency of $ 8 $ and contains Allergens $ 2 $ and $ 3 $ .
- Person $ 1 $ may be given any drug.
- Person $ 2 $ may not be given a drug containing Allergen $ 1 $ .
- Person $ 3 $ may not be given a drug containing Allergen $ 2 $ .
- Person $ 4 $ may not be given a drug containing one or more of Allergens $ 1 $ and $ 2 $ .
### Constraints
- $ 1 \leq N \leq 100 $
- $ 1 \leq A_i \leq 100 $
- $ A_i \neq A_j $ if $ i \neq j $ .
- $ 0 \leq C_i $
- $ 0 \leq \sum_{i=1}^N C_i \leq 10^5 $
- $ 1 \leq X_{i,j} \leq 2 \times 10^5 $
- $ X_{i, j} \neq X_{i, k} $ if $ j \neq k $ .
- $ 1 \leq Q \leq 10^5 $
- $ 0 \leq D_p $
- $ 0 \leq \sum_{p=1}^Q D_{p} \leq 10^5 $
- $ 1 \leq Y_{p,q} \leq 2 \times 10^5 $
- $ Y_{p,q} \neq Y_{p,r} $ if $ q \neq r $ .
- All values in input are integers.