During the contest i have thought about the HLD solution for the problem PHSTREE i have understand about the decomposition of the tree so that we can traverse atmost log n subtree to get the result. But when it comes to answer the query in a single branch we need to use the fenwick tree along with the **compressed** weight (finding the weight takes logn by binary search), then using the fenwick tree to get the result which also takes logn time so solution should be **NlogSquaredN** solution.

But when forming the fenwick tree over the single branch i got stuck. I have seen that people used to build the segment tree easily on a single branch of the tree but fenwick tree i do not understand how to do that. Would you please help me clearing my doubts **about my approach**. I would be very thankful to you.