Skip to content
Embercode
✕
Advanced graphsQuick quiz

Tree queries

8 questions. Covers Heavy-light decomposition: path and subtree queries on a tree.

Questions 1 to 5 of 8

  1. 1. An AI tool says that binary lifting answers each LCA query in O(1) time once the table is built, the same as an Euler tour with a sparse table. Is this right?
  2. 2. A binary lifting table is built for a tree with n = 200000 vertices, using the loop while ((1 << LOG) <= n) LOG++. How many levels does LOG end up as?

    Type a number.

  3. 3. Take the 7-vertex tree from the tree DP lesson: edges 0-1, 0-2, 1-3, 1-4, 2-5 and 5-6, rooted at 0. The sum of distances from vertex 0 to all other vertices is 11. Using the rerooting rule ans[v] = ans[p] - sz[v] + (n - sz[v]), what is the sum of distances from vertex 1? Here sz[1] = 3.

    Type a number.

  4. 4. An AI wrote heavy-light decomposition code for path sums. Its loop decides which vertex to move up by comparing depth[u] and depth[v], the depths of the two current vertices, not the depths of their chain heads. It passes the sample, where both ends are on one chain. What is the most likely failure?
  5. 5. Which statements about heavy-light decomposition are true? Assume the decomposition uses a DFS that visits the heavy child first.

    Pick every answer that is true.

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.