Data Structures & AlgorithmsVery hardCodeforces Div 2 C

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

  1. A. 15
  2. B. 13
  3. C. 4
  4. D. 26

Correct answer: A. 15

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic