You are given a tree with root node as 1. Every edge in the tree is undirected. Each node has been assigned a value. You have to handle two kinds of queries.
1 X Y : change value of node X to Y
0 X Y : Check whether the path from node X to node Y is dancing. Path is dancing if all values form alternating sequence while travelling from node X to node Y.
Eg. of alternating values sequence: 4 9 6 7 2 100 18.
Input
First line contains a number N and Q as input. Next N-1 lines contains u and v denoting there is an undirected edge between node u and v. Next line contains N integers denoting value of each node
Output
Output for only query type 0 u v whether the path from node u to v is alternating or not . Output should be YES or NO
Constraints
1≤ N ≤ 5*10^4
1≤ u ≤ v ≤ N
1≤ q ≤ 10^5
0≤ value of node ≤ 100
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
Login to unlock the editorial