Data Structures & AlgorithmsVery hardCodeforces Div2 C · ICPC regional

A tree has these parent→child edges (treat them as undirected): 48→16, 48→86, 99→64, 42→9, 48→91, 86→42, 86→88, 57→11, 42→57, 86→99. For a node x, let D(x) be the sum of the distances, in edges, from x to every node of the tree. What is the minimum value of D(x) over all nodes x?

  1. A. 22
  2. B. 17
  3. C. 36
  4. D. 10

Correct answer: B. 17

The minimum of D(x) is attained at the tree's median, which can be found by rerooting one edge at a time. The root's total, the maximum total, or the node of highest degree are not the minimum.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic