Data Structures & AlgorithmsVery hardCodeforces Div 2 C

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

  1. A. 21
  2. B. 24
  3. C. 3
  4. D. 36

Correct answer: B. 24

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