Maximum Weight Independent Set
Challenge on lesson: Checkpoint — In/Out Tree DP
CHALLENGE
Difficulty: advanced+25 XP
**Bài toán.** A rooted tree with n nodes (root 1; parents given for v = 2..n), node values val[1..n] (possibly negative). Print the maximum total value of a set of nodes with no two adjacent — the empty set is legal. **Constraints:** 1 ≤ n ≤ 200 000; |val[i]| ≤ 10^9; answer fits in long long. In/out DP in one iterative post-order pass: O(n).
Press Submit to check your solution.
Back to lesson: Checkpoint — In/Out Tree DP