Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional

A tree has vertices with values in brackets: X[-1], L[8], G[-1], S[7], F[8], K[6]. The edges are X–L, L–G, X–S, X–F, S–K. A path is any sequence of adjacent vertices with no repeated vertex (a single vertex is a path). What is the maximum possible sum of values along one path?

  1. A. 13
  2. B. 8
  3. C. 29
  4. D. 20

Correct answer: D. 20

A DP that combines the two best downward chains at each vertex finds 20. Paths restricted to a single ancestor-to-descendant line give at most 13, and paths that start at the root give 12.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic