You are given a tree with N nodes and N-1 edges.Initially the root of the tree is 1. There are two types of queries.
Type 1 : 1 R ( Change the root of the tree to R. )
Type 2 : 2 u v ( Check if v lies in the subtree of u)
Input format
First line of the the input contain N ( the number of nodes in the tree ). N-1 following lines contain two integer input u,v which represent an edge between u and v.Next line contain an input Q ( The number of queries ).For each query you will be given an integer denoting the type of the query.for type 1 you will be given an integer R and for type 2 you will be given two integer u,v.
Output format
For each query of Type 2 print "YES" if v lies in the subtree of u else print "NO".
Constraints
- \(1<=N<=2*10^{5}\)
- \(1<=u,v,R<=N\)
- \(1<=Q<=10^{5}\)
10 1 4 2 3 6 7 8 9 5 17 6
6
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
No editorial available for this problem.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor