Data Structures & AlgorithmsVery hardCodeforces Div 2 C

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

  1. A. 22
  2. B. 5
  3. C. 27
  4. D. 42

Correct answer: C. 27

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic