I have a task:
Given a tree with n vertices. From the start all the vertices are not painted. For O((n+q)*sqrt(n+q)) need to answer to q requests:1) paint vertice V;2) find the closest to the V painted vertice.
I split all the vertices in heavy and light (heavy - vertices with power >= sqrt(n)) and try to do task for heavy directly and count answer "by hands" for light, but I'm stuck :(