Khanj is a chubby personality (you read it full) and has little edge! He recently…
- User
Khanj is a chubby personality (you read it full) and has little edge! He recently decided to go on a diet and usually sticks to it.
Khanj loses control only when it sees a tree whose vertices are colored, and if the maximum distance between two discolored vertices in the tree x be x, he x x Juice will eat sweets.
We have a tree with n n vertices and k k color, we don't know the color of some vertices, their color with number 0 0 is shown and color the rest of the vertices with numbers 1 1 to k k. Since we are very concerned about Khanaj's diet, we want him to eat the least amount of sweets when he sees this tree. So, we try to match the vertices whose color is not known with colors 1 1 to k Let's paint that color i iam a i a i Load appears and the maximum distance between 2 Minimize 2 non-uniform vertices. It is guaranteed that the sum of colors n n is
Also q q times a vertex is selected, and its color changes, such that if its color 1 1 to k Let k be its color 0 becomes 0 (becomes colorless) and if it is colorless, its color will be a number of 1 1 to k k becomes (guarantees no color after this operation i more than a i a i load will not appear)
You have been asked q + 1 Print a number q+1, which indicates at least how many candies will be eaten by Khanj at the beginning and after each change in the tree?
input In the first line, enter two numbers n n and k k has arrived.
in n
1 n−1 lines after each line, two numbers u u and v v is there, which means the existence of an edge from the vertex u u to vertex v v is
In the next line k k number comes that number i i is equal to a i a i is
In the next line, the number q q has arrived.
in q q Next line, any line 2 2 pieces x x and c c is there, which means changing the color of the vertex x x to color c c is If c
0 c = 0, it means that this vertex will be colorless.
1 ≤ n , k , q ≤ 100
000 1≤n,k,q≤100,000 1 ≤ u , v , x ≤ n 1≤u,v,x≤n 0 ≤ c ≤ k 0≤c≤k
output in q + 1 q+1 output line, print the values mentioned in the question in order.
Sub issues Constraint score subproblem 1 15 q ≤ 10 q≤10, n ≤ 9 n≤9 2 15 k
2 k=2, q
0 q=0 3 20 q
0 q=0 450 without additional restrictions Example Sample entry 1 3 2 1 2 2 3 2 1 4 1 1 2 1 2 0 2 2 Plain text Sample output 1 1 1 2 1 1 write in c++
- Assistant