teacher
Sign in

Small-to-Large Merging and DSU on Tree

Merge the smaller set into the larger so each element moves O(log n) times, and reuse that idea as DSU on tree to answer subtree queries.

45 minCF 1800–24005 interactive9 problems

The problem

A rooted tree has a colour on every vertex. For every vertex vv, report the number of distinct colours in the subtree of vv (the vertex and everything below it).

1 of 8