Practice: Binary lifting
0 of 4 solved
About these problems
Apply, Connect, Reason and Stretch describe difficulty within this topic, not an official contest rating. Open any problem in any order; reading the chapter first is optional.
- 1Kth ancestorA tree has n vertices, numbered 1 to n, and is rooted at vertex 1. Each query v k asks you to move k steps upward from v, where one step goes from a vertex to its parent. Print the vertex reached, or 0 if v has fewer than k ancestors. When k = 0 the answer is v.ApplyNot started
- 2Repeated successorThere are n vertices, numbered 1 to n, and each vertex v has exactly one successor fv. Cycles and self-loops (fv = v) are allowed. Print, for each query v k, the vertex reached by starting at v and moving to the successor exactly k times.ConnectNot started
- 3Tree route distanceAn unweighted tree has n vertices, numbered 1 to n. Print, for each of q queries a b, the distance between vertices a and b, measured in edges.ReasonNot started
- 4A stop along the routeAn unweighted tree has n vertices, numbered 1 to n. Print, for each of q queries a b k, the vertex reached after walking k edges along the unique path from a toward b, or 0 if that path has fewer than k edges. When k = 0 the answer is a.StretchNot started