#P5311. [Ynoi2011] 成都七中

[Ynoi2011] 成都七中

Description

You are given a tree with nn nodes. Each node has a color. There are mm queries.

Each query gives parameters l r xl\ r\ x. You need to output:

Keep all nodes whose indices are in [l,r][l,r] in the tree. In the connected component that contains xx, output the number of distinct colors.

Each query is independent.

Input Format

The first line contains two integers n,mn,m.

The second line contains nn integers representing the color of each node.

Then follow n1n-1 lines. Each line contains two integers xx and yy, indicating there is an edge between xx and yy.

Then follow mm lines. Each line contains three integers l r xl\ r\ x, representing one query.

Output Format

For each query, output one line with one integer, the answer.

5 4
1 3 5 3 5
1 2
2 3
3 4
4 5
1 5 1
2 4 3
3 4 3
1 4 3
3
2
2
3

Hint

Idea: nzhtl1477, Solution: nzhtl1477, Code: created_equal1, Data: nzhtl1477.

Constraints: For 100%100\% of the testdata, all numbers that appear are in [1,105][1,10^5], and it is guaranteed that for each query lxrl \le x \le r.

Translated by ChatGPT 5