“Asking the online judge” is just the perfect way to achieve it. XD
To achieve nlog^2n, you can simply store the distance from a node u to all its ancestors before binary search …
I’m sorry I didn’t understand what you mean by asking the online judge. I see people often refer to the online judge; could you please tell me what it is?
It just means submitting your solution with different values of bucket sizes. One of them will surely be the optimal one. XD