1 teams scored 7 points on this task, for a maximum score of 7, an average score of 7 and a median score of 7.
You are given a weighted tree with N nodes numbered from 0 to N-1. Let cost(u, v) denote the bitwise AND of all edge weights on the shortest path between nodes u and v. The cost of the tree is the sum of cost(u, v) across all 0 < u < v < N. More formally, the cost of the tree is: \sum_u=0^N-2 \sum_v=u+1^N-1 cost(u, v) You have to process Q queries described by a triplet of integers U_j, V_j, X_j: the weight of the edge connecting nodes U_j and V_j changes to X_j. Print the cost of the tree before the first query and following each query.