Data Structures & AlgorithmsHardCodeforces Div 2 C

Tree on vertices 0 to 7 with weighted edges (u–v (w)): 0–1 (9), 0–6 (2), 2–5 (4), 3–4 (9), 0–5 (7), 1–4 (1), 1–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. 30
  2. B. 19
  3. C. 5
  4. D. 38

Correct answer: A. 30

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