#t523. 亲戚
亲戚
Relatives
Problem Background
Special for beginners, ^_^
Problem Description
You may not know it, but one of your friends is your relative. He could be the great-grandson of the nephew of your wife's cousin's daughter's grandson. If we had the complete family tree, it would be feasible to tell whether two people are relatives, but if the two people's lowest common ancestor is separated from them by several generations, making the family tree huge, then checking the relationship is beyond human power. In this case, the best helper is a computer. To simplify the problem, you will be given some information about relative relationships, such as Marry and Tom are relatives, Tom and Ben are relatives, and so on. From this information you can deduce that Marry and Ben are relatives. Please write a program that answers our questions about relative relationships as fast as possible.
Input Format
The input consists of two parts.
The first part begins with . is the number of people involved in the questions (). These people are numbered .
The following lines () each contain two numbers , meaning and are known to be relatives.
The second part begins with . The following lines contain queries (), each line is , asking whether and are relatives.
Output Format
For each query , output one line: if and are relatives, output Yes; otherwise output No.
Sample Input
10 7
2 4
5 7
1 3
8 9
1 2
5 6
2 3
3
3 4
7 10
8 9
Sample Output
Yes
No
Yes
Constraints
Time limit: 1s; memory limit: 1024 KiB for each test case.