#P5311. [Ynoi2011] 成都七中
[Ynoi2011] 成都七中
Description
You are given a tree with nodes. Each node has a color. There are queries.
Each query gives parameters . You need to output:
Keep all nodes whose indices are in in the tree. In the connected component that contains , output the number of distinct colors.
Each query is independent.
Input Format
The first line contains two integers .
The second line contains integers representing the color of each node.
Then follow lines. Each line contains two integers and , indicating there is an edge between and .
Then follow lines. Each line contains three integers , 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 of the testdata, all numbers that appear are in , and it is guaranteed that for each query .
Translated by ChatGPT 5
京公网安备 11011102002149号