Given a tree and a node , who is the -th ancestor of ?
The -th ancestor is the node you reach by going up steps toward the root. For example, if has parent , then is the st ancestor. The parent of is the nd ancestor. The root is the depth[v]-th ancestor.
The naive approach jumps one parent at a time, taking per query. If is close to and you have queries, that is total.