Data Structures & AlgorithmsVery hardCodeforces Div 2 C

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

  1. A. 19
  2. B. 3
  3. C. 30
  4. D. 20

Correct answer: D. 20

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic