Data Structures -> DSU On Tree / Small-To-Large
Rooted-tree subtree queries where each child contributes a mergeable container and smaller containers are merged into larger surviving ones.
- Topic slug:
data-structures/dsu-on-tree
- Tutorial page: Open tutorial
- Ladder page: Open ladder
- Repo problems currently tagged here:
1
- Repo companion pages:
6
- Curated external problems:
2
Microtopics
- small-to-large-merging
- subtree-container
- frequency-map-merge
- sack-compare-point
- subtree-distinct
- amortized-doubling
Learning Sources
Practice Sources
Repo Companion Material
Curated External Problems
Core
| Problem |
Source |
Difficulty |
Context |
Style |
Prerequisites |
Tags |
Why it fits |
| Distinct Colors |
CSES |
Hard |
Subtree Queries |
Small-To-Large Merging; Subtree Frequency Maps; Offline Aggregation |
Rooted Tree; Frequency Maps; Subtree Traversal |
Distinct Values; Subtree Aggregation; Small-To-Large |
The cleanest first benchmark where each subtree owns a mergeable color-frequency container and the whole optimization is just small-to-large merging. |
Stretch
| Problem |
Source |
Difficulty |
Context |
Style |
Prerequisites |
Tags |
Why it fits |
| Lomsat gelral |
Codeforces |
Hard |
Subtree Queries |
Small-To-Large Merging; Frequency Aggregation; Heavy Child Compare Point |
DSU On Tree; Frequency Maps; Subtree Traversal |
Color Frequency; Subtree Aggregation; Small-To-Large |
A classic follow-up where the merged container must track richer frequency information than just distinct-count size. |
Repo Problems
| Code |
Title |
Fit |
Difficulty |
Pattern |
Note |
Solution |
DISTINCTCOLORS |
Distinct Colors |
primary |
hard |
- |
Note |
Code |
Regeneration
python3 scripts/generate_problem_catalog.py