Tree Points

Problem Overview

  • Maximize total points on a tree rooted at 0 by choosing at each node A[j]-K or floor(A[j]/2), where halving applies to the whole subtree.
  • Input: g_nodes, edges (g_from, g_to), values A, K; Output: a long with the maximum sum.
  • Constraints: n ≤ 1e5; A, K ≤ 1e9; a node can be collected only after its parent (root exempt), totals may be negative.
  • Context: hierarchical decision trade-offs with subtree propagation.
  • From Deshaw interviews: a coding interview problem and common interview question on trees.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: