Data Structures & AlgorithmsHardCodeforces Div2 C · ICPC regional

A tree has these parent→child edges (treat them as undirected): 89→51, 30→28, 81→93, 89→4, 28→69, 68→30, 69→29, 51→81, 4→38, 38→68. 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. 34
  2. B. 55
  3. C. 10
  4. D. 30

Correct answer: D. 30

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