You are given a historical family tree of the noble kingdom, represented as a tree structure. The tree contains information about generations of ancestors and descendants. Your goal is to answer a series of queries in a way that helps people establish their ancestral connections.For each query, you will receive two names, let's call them Person X and Person Y. Person 1 is the root of the family tree. Your task is to determine whether Person X is an ancestor of Person Y or not. If Person X is indeed an ancestor of Person Y, you should respond with YES otherwise, you should reply with NO.Think of yourself as the custodian of this invaluable historical record, helping the kingdom's residents trace their noble lineage. Can you provide accurate responses to these queries and unveil the ancestral ties that bind the kingdom's inhabitants together?
Input Format:
Output Format:
For each query, output either YES if Person X is an ancestor of Person Y, or NO if Person X is not an ancestor of Person Y.
Constraints:
1≤N,Q≤2∗1051≤U,V≤N1≤X,Y≤N
For query 1 : 1 is the ancestor of 3
For query 2 : 6 is not the ancestor of 5
For query 3 : 2 is not the ancestor of 3