Data Structures & AlgorithmsHardICPC regional · GATE CS top band

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

  1. A. 20
  2. B. 12
  3. C. 3
  4. D. 33

Correct answer: A. 20

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic