Frequent color - MarisaOJ: Marisa Online Judge

Frequent color

Time limit: 1000 ms
Memory limit: 256 MB
Given a tree of n vertices rooted at 1, vertex i has color Ai. Given q queries, each of the form (u,x), count the number of colors appear at least x times in the subtree rooted at u. ### Input - The first line contains two integers n,q. - 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. - The next q lines, each line contains two integers u,x, a query. ### Output - Print the answer for each query. ### Constraints - 1≤n,q≤105. - 1≤Ai≤105. - 1≤u,v,x≤n. ### Example Input: 431222122324121123 Output: 121