Data Structures & AlgorithmsHardGATE CS · ICPC regional

Weighted tree on vertices 0 to 8 with edges 0–1 (6), 1–2 (7), 0–3 (8), 0–4 (1), 0–5 (1), 5–6 (6), 2–7 (2), 4–8 (2). What is the largest possible sum of edge weights on a simple path between two vertices (the weighted diameter)?

  1. A. 5
  2. B. 15
  3. C. 33
  4. D. 23

Correct answer: D. 23

Two BFS/DFS sweeps on a tree give the heaviest path 23. Summing all weights, counting edges (5), or measuring from vertex 0 only (15) answer different questions.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic