Distinct colors - MarisaOJ: Marisa Online Judge

Distinct colors

Time limit: 500 ms
Memory limit: 256 MB
Given a tree of n vertices rooted at 1, vertex i has color Ai. For each vertex u, count the number of distinct colors in the subtree rooted at u. ### Input - The first line contains an integers n. - The second line contains n integers Ai. - The next n−1 lines, each line contains two integers u,v, there is an edge between u and v. ### Output - Print n integers, the ith is the answer for vertex i. ### Constraints - 1≤n≤105. - 1≤Ai≤105. - 1≤u,v≤n. ### Example Input: 41222122324 Output: 2111