Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Distinct Colors in a Subtree

Each node of a tree rooted at 1 has a color. For each query node x print how many distinct colors appear in the subtree of x.

Constraints

1 <= n, q <= 10^5 1 <= color <= n

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.