1. Two Roles for Every Node Optimal
Intuition
Each node plays two parts, and keeping them apart is the entire problem. As a PASS-THROUGH it hands its parent a chain: itself plus at most ONE child's contribution, because a path cannot fork and still continue upward. As a SUMMIT it may join both children and go no higher — that is where the best answer might live. So the recursion returns the pass-through value while a running best records every summit. A negative contribution is dropped to zero: a path may simply decline to include it.
Algorithm
1. An empty node contributes nothing.
2. Take each child's contribution, clamped at zero.
3. The summit through this node is its value plus both contributions — offer that to the running best.
4. Return this node's value plus the LARGER single contribution, which is what its parent can use.
Time & Space
Time O(n). Space O(h). Seed the best at negative infinity so an all-negative tree still answers with its least-bad node.