Problems > No Two Neighbours Chosen > Editorial

No Two Neighbours Chosen — Solution & Editorial

Back to the Problem

Tree DP with two states per node (take / skip): take[u] = w[u] + ∑ skip[child]; skip[u] = ∑ max(take, skip) over children. Iterate over a post-order to avoid recursion limits.

Complexity: O(N)