Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

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

  1. A. 25
  2. B. 4
  3. C. 17
  4. D. 28

Correct answer: A. 25

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic