1 'U' 'V': Reverse the order of all the integers on the path between 'U' and 'V'.
2 'U' 'V': Print the sum of all the integers on the path between 'U' and 'V'.
The first line contains two space-separated integers, ‘N’ and ‘Q’, denoting the number of vertices of the tree and the number of queries.
The next N-1 lines will contain two space-separated integers u and v, denoting an undirected edge between city u and city v.
The next line contains ‘N’ space-separated integers denoting the value associated with each node.
The next q lines contain three space-separated integers representing the queries of both types.
Output for each query of type two only, whether the path between the two cities of that query is alternating or not.
Output for each query will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= N,Q <= 10^4
1 <= u,v <= N
1 <= value[i] <= 10^4
Where value[i] represents the value associated with the node.
Time Limit: 1 sec.
We will use heavy-light decomposition to solve this problem. The idea of this algorithm is that we will try to break the given tree into some segments where we can apply the segment tree to process each query in logarithmic time.
Algorithm:
Blueprint
Plantation
Capturing Grid
Rotting Oranges
Distance to a Cycle in Undirected Graph