you give rooted tree root vertex 1 each vertex colour colourlet colour c dominate subtree vertex v colour appear subtree vertex v time colour c so possible colour dominate subtree vertexthe subtree vertex v vertex v vertex contain vertex v path rootFor vertex v find sum dominate colours subtree vertex v