#P5526. [Ynoi2012] 惊惶的 SCOI2016
[Ynoi2012] 惊惶的 SCOI2016
Problem Description
You are given a tree with nodes. Each node has a color. There are modifications. For each modification, you need to output the sum, over all directed simple paths in the tree, of the number of distinct colors on the path.
Input Format
The first line contains two integers and .
The second line contains integers (), where is the initial color of node .
The next lines each contain two integers (), indicating that there is an edge between and .
Then follow lines, each containing two integers (), meaning to change the color of node to .
Output Format
Output lines, each containing one integer: the sum of the number of colors over all paths in the tree for the initial tree, and the value after each modification.
5 3
1 2 1 2 3
1 2
1 3
3 4
3 5
3 3
4 1
4 3
47
51
49
45
6 1
1 1 1 1 1 1
1 2
2 3
3 4
4 5
5 6
1 2
36
46
Hint
Idea: nzhtl1477, Solution: nzhtl1477, Code: nzhtl1477, Data: nzhtl1477
For of the testdata, and .
Translated by ChatGPT 5