Problem6958--POJ2443 - Set Operation

6958: POJ2443 - Set Operation

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

You are given $N$ sets, the $i$-th set (represent by $S(i)$) have $C(i)$ element (Here "set" isn't entirely the same as the "set" defined in mathematics, and a set may contain two same element). 
Every element in a set is represented by a positive number from $1$ to $10000$. 
Now there are some queries need to answer. 
A query is to determine whether two given elements $i$ and $j$ belong to at least one set at the same time. In another word, you should determine if there exist a number $k\ (1 \leq k \leq N)$ such that element $i$ belongs to $S(k)$ and element $j$ also belong to $S(k)$.
给定多个集合,让你判断数字 $i$ 和 $j$ 是否同时存在于这里面的某个集合中。

Input

First line of input contains an integer $N\ (1 \leq N \leq 1000)$, which represents the amount of sets. 
Then follow $N$ lines. Each starts with a number $C(i)\ (1 \leq C(i) \leq 10,000)$, and then $C(i)$ numbers, which are separated with a space, follow to give the element in the set (these $C(i)$ numbers needn't be different from each other). 
The $N + 2$ line contains a number $Q\ (1 \leq Q \leq 200,000)$, representing the number of queries. 
Then follow $Q$ lines. Each contains a pair of number $i,j\ (1 \leq i, j \leq 10000$, and $i$ may equal to $j$), which describe the elements need to be answer.

Output

For each query, in a single line, if there exist such a number $k$, print "Yes"; otherwise print "No".

Sample 1 Input

3
3 1 2 3
3 1 2 5
1 10
4
1 3
1 5
3 5
1 10

Sample 1 Output

Yes
Yes
No
No

HINT

相同题目:POJ 2443

Source/Category