Data Structures & AlgorithmsModerateCodeforces Div 2 C

Tree on vertices 0 to 7 with weighted edges (u–v (w)): 4–6 (2), 0–2 (1), 5–7 (3), 1–2 (9), 4–7 (7), 1–6 (8), 2–3 (5). What is the diameter of the tree, i.e. the largest sum of edge weights over any path between two vertices?

  1. A. 30
  2. B. 6
  3. C. 35
  4. D. 34

Correct answer: D. 34

The heaviest path has weight 34, confirmed by all-pairs distances. The eccentricity of vertex 0 (30) measures paths from a single vertex, and the hop-count diameter (6) ignores the weights.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic