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. This problem shows up everywhere: LCA queries, path queries, level ancestor questions. Solving it fast lets you handle dozens of other problems.