Skip to content

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

Source Type
USACO Guide Small-To-Large Merging Reference
OI Wiki DSU on Tree Reference
SOI Wiki Smaller to Larger Reference

Practice Sources

Source Type
CSES Distinct Colors Practice
Codeforces Lomsat gelral Practice

Repo Companion Material

Material Type
DSU On Tree hot sheet quick reference
Distinct Colors note anchor note
DSU on tree starter route starter route
DSU tutorial adjacent tutorial
Tree DP tutorial compare point
Mo's Algorithm tutorial compare point

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