Data Structures & AlgorithmsVery hardCodeforces Div 2 C

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

  1. A. 18
  2. B. 25
  3. C. 6
  4. D. 33

Correct answer: B. 25

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