You are given a tree of size N rooted at node 1.
The edges are given by the vector P of size N-1 where ith element represents an edge between i+1 and P[i]. (1-based indexing)
You need to answer Q queries on it.
In each query, you are given L and R.
You need to find such a node V such that all leaves with labels between L and R inclusive, lie in its subtree.
The node V should also be at maximum height as possible.
If there does not exist any leaf with label between L to R, return -1 for that query.
Answers
Answered by
2
Answer:
Similar questions