Shan is a kind of fish and looks very beautiful in dress. There is a tree whose root is 1. Every node i in this tree owns a weight W[i]W[i] W[i], satisfying that ifxx x is an ancestor ofyy y then W[x]≤W[y]W[x] le W[y]W[x]≤W[y]. Shan have several questions, each question can be represented as a pair(x,k), Shan wants to find the biggest node y such that yk≤W[lca(x,y)]y - k le W[lca(x,y)]yk≤W[lca(x,y)]. Shan is not happy today, can you help her to answer these questions?
Shan is a kind of fish and looks very beautiful in dress. There is a tree whose root is 1. Every node i in this tree owns a weight W[i] W[i] W[i] , satisfying that if x x x is an ancestor of y y y then W[x]≤W[y]W[x] le W[y]W[x]≤W[y]. Shan have several questions, each question can be represented as a pair(x,k), Shan wants to find the biggest node y such that y−k≤W[lca(x,y)]y - k le W[lca(x,y)]y−k≤W[lca(x,y)]. Shan is not happy today, can you help her to answer these questions?
(图片来源网络,侵删)