#P2664. 树上游戏
树上游戏
Description
lrb has a tree, and each node has a color. Given a color sequence of length , define as the number of distinct colors on the simple path from node to node .
Now he wants you to compute all .
For of the testdata, . For of the testdata, .
Input Format
The first line contains an integer , the number of nodes in the tree.
The second line contains integers, the colors of the nodes: .
Each of the next lines contains two integers , meaning there is an edge between and .
Output Format
Output lines. The -th line should be .
5
1 2 3 2 3
1 2
2 3
2 4
1 5
10
9
11
9
12
Hint
$$sum_1=s(1,1)+s(1,2)+s(1,3)+s(1,4)+s(1,5)=1+2+3+2+2=10$$$$sum_2=s(2,1)+s(2,2)+s(2,3)+s(2,4)+s(2,5)=2+1+2+1+3=9$$$$sum_3=s(3,1)+s(3,2)+s(3,3)+s(3,4)+s(3,5)=3+2+1+2+3=11$$$$sum_4=s(4,1)+s(4,2)+s(4,3)+s(4,4)+s(4,5)=2+1+2+1+3=9$$$$sum_5=s(5,1)+s(5,2)+s(5,3)+s(5,4)+s(5,5)=2+3+3+3+1=12$$Translated by ChatGPT 5
京公网安备 11011102002149号