I can't come to an efficient algorithm to this problem except O( M log ^3 N ) using binary search + segment tree + heavy light decomposition. There is an ( M log ^ 2 N) solution which will TLE. The intended one is O(M log N) solution, can anyone please explain any of them? Thanks in advance
![:)](./images/smilies/icon_smile.gif)