Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

A binary tree has these nodes: node 10 (value 3): left none, right none; node 14 (value 2): left 62, right 53; node 24 (value 6): left none, right none; node 25 (value -5): left none, right none; node 53 (value -8): left none, right none; node 56 (value 3): left 10, right none; node 57 (value 0): left 14, right 95; node 62 (value 5): left none, right 88; node 67 (value -6): left 56, right 57; node 88 (value -4): left none, right none; node 95 (value 4): left 25, right 24. A path is any sequence of nodes in which consecutive nodes are joined by an edge, with no node repeated; a single node is a path. The value of a path is the sum of its node values. What is the maximum value of any path?

  1. A. 4
  2. B. 17
  3. C. 6
  4. D. 10

Correct answer: B. 17

The best path may bend at any node, start and end anywhere, and can be a single node. Restricting it to start at the root, to be one node, or to pass through the root gives smaller values.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic