CustomCC0-1.0#ct-p2-031700
Subtree Token Harvest
Summary
- •Phase 2 / tree-dp-intro
- •Reasoning-first competitive programming drill
Problem Description
Each tree node has token value. Choose up to k disjoint subtrees maximizing total tokens.
How to read this problem in plain language:
- This is a Phase 2 reasoning drill focused on tree-dp-intro.
- Typical lenses to test first: tree, dfs, dp.
- Constraints reminder: 1 <= n <= 2e5, k <= 200
Mini examples for mental simulation:
1) Boundary example: Answer must be 0. Explain expected behavior and why naive logic may fail.
2) Adversarial example: Choosing fewer than k subtrees may be optimal.
Lite-mode writing target:
- Write 1~2 observations that shrink the search space.
- Name one final algorithm and state target complexity explicitly.
- Validate with at least 2 edge cases and one hand simulation.
Constraints
- •1 <= n <= 2e5, k <= 200
Analysis
Key Insight
Limit DP dimension to k to avoid O(n^2). This step should reduce search space or formalize correctness. State why this insight changes your algorithm choice.
treedfsdpinduction