Tree
Time Limit: 16000/8000 MS (Java/others) memory limit: 65536/65536 K (Java/Others)
Total submission (s): 41 accepted submission (s): 10
Problem descriptionyou are given a tree with N nodes which are numbered by integers 1 .. n. Each node is associated with an integer as the weight.
Your task is to deal with M operations of 4 types:
1. delete an edge (x, y) from the tree, and then add a new edge (a, B). We ensure that it still constitutes a tree after adding the new edge.
2. Given two nodes A and B in the tree, change the weights of all the nodes on the path connecting node A and B (including node A and B) to a participant value x.
3. Given two nodes A and B in the tree, increase the weights of all the nodes on the path connecting node A and B (including node A and B) by a participant value D.
4. given two nodes A and B in the tree, compute the second largest weight on the path connecting node A and B (including node A and B ), and the number of times this weight occurs on the path. note that here we need the strict second largest weight. for instance, the strict second largest weight of {3, 5, 2, 5, 3} is 3.
Inputthe first line contains an integer T (t <= 3), which means there are t test cases in the input.
For each test case, the first line contains two integers n and M (n, m <= 10 ^ 5 ). the second line contains N integers, and the I-th integer is the weight of the I-th node in the tree (their absolute values are not larger than 10 ^ 4 ).
In next N-1 lines, there are two integers A and B (1 <= A, B <= N), which means there exists an edge connecting node A and B.
The next M lines describe the operations you have to deal with. In each line the first integer is C (1 <= C <= 4), which indicates the type of operation.
If C = 1, there are four integers x, y, a, B (1 <= X, Y, a, B <= N) after C.
If C = 2, there are three integers a, B, x (1 <= A, B <= N, | x | <= 10 ^ 4) after C.
If C = 3, there are three integers a, B, d (1 <= A, B <= N, | d | <= 10 ^ 4) after C.
If C = 4 (it is a query operation), there are two integers A, B (1 <= A, B <= N) after C.
All these parameters have the same meaning as described in Problem description.
Outputfor each test case, first output "case # X:" "(X means case ID) in a separate line.
For each query operation, output two values: the second largest weight and the number of times it occurs. if the weights of nodes on that path are all the same, just output "all same" (without quotes ).
Sample Input
23 21 1 21 21 34 1 24 2 37 75 3 2 1 7 3 61 21 33 43 54 64 74 2 63 4 5 -14 5 71 3 4 2 44 3 62 3 6 54 3 6
Sample output
Case #1:ALL SAME1 2Case #2:3 21 13 2ALL SAME
Question: RT
Idea: LCT template question. It should be noted that when the update is delayed downward, you must first update one chain and one number, and then update and replace it with one number.
During the competition, the two operations were reversed, resulting in 10 transactions. It was also too drunk ~
2014 Anshan network qualifiers 1006 (LCT template) hdu5002