Data Structures & AlgorithmsVery hardCodeforces Div 2 C

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

  1. A. 9
  2. B. 16
  3. C. 3
  4. D. 29

Correct answer: B. 16

The heaviest path has weight 16, confirmed by all-pairs distances. The eccentricity of vertex 0 (9) 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