Data Structures & AlgorithmsHardGATE CS · ICPC regional

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

  1. A. 30
  2. B. 6
  3. C. 27
  4. D. 14

Correct answer: C. 27

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic