Data Structures & AlgorithmsHardGATE CS · ICPC regional

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

  1. A. 18
  2. B. 31
  3. C. 19
  4. D. 3

Correct answer: C. 19

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic