Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

A rooted tree has these parent→child edges: 7→75, 11→34, 11→99, 89→80, 52→11, 19→91, 60→19, 35→60, 60→89, 80→25, 91→52, 7→43, 35→7. A node counts as its own ancestor. What is the lowest common ancestor of the nodes 43 and 60, i.e. the deepest node that is an ancestor of both?

  1. A. 7
  2. B. 60
  3. C. 43
  4. D. 35

Correct answer: D. 35

The LCA is the deepest common ancestor: lift the deeper node to the same depth, then climb both together (binary lifting does this in O(log n)). Answering the root, the parent of one node, or a node itself is the trap.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic