Data Structures & AlgorithmsHardCodeforces Div 2 C

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

  1. A. 28
  2. B. 7
  3. C. 29
  4. D. 34

Correct answer: C. 29

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic