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.
The problem
A rooted tree has a colour on every vertex. For every vertex , report the number of distinct colours in the subtree of (the vertex and everything below it).
1 of 8