#Q140. 「一本通 4.5 例 1」树的统计

「一本通 4.5 例 1」树的统计

Description

Original source: ZJOI 2008

There is a tree with nn nodes, numbered from 11 to nn. Each node has a weight ww. You are required to perform the following operations on the tree:

  1. CHANGE u t: Change the weight of node uu to tt;
  2. QMAX u v: Query the maximum weight of nodes on the path from node uu to node vv;
  3. QSUM u v: Query the sum of weights of nodes on the path from node uu to node vv.

Note: The nodes on the path from node uu to node vv include both uu and vv themselves.

Input Format

The first line contains an integer nn, representing the number of nodes;

Next, n1n-1 lines follow, each containing two integers aa and bb, indicating an edge between node aa and node bb;

The following line contains nn integers, where the ii-th integer wiw_i represents the weight of node ii;

The next line contains an integer qq, representing the total number of operations;

Subsequent qq lines each describe an operation in the form of CHANGE u t, QMAX u v, or QSUM u v.

Output Format

For each QMAX or QSUM operation, output an integer representing the result.

Sample 1

4
1 2
2 3
4 1
4 2 1 3
12
QMAX 3 4
QMAX 3 3
QMAX 3 2
QMAX 2 3
QSUM 3 4
QSUM 2 1
CHANGE 1 5
QMAX 3 4
CHANGE 3 6
QMAX 3 4
QMAX 2 4
QSUM 3 4

4
1
2
2
10
6
5
6
5
16

Constraints & Hints

For 100%100\% of the data, 1n3×1041\le n \le 3\times 10^4, 0q2×1050 \le q \le 2\times 10^5. It is guaranteed that during the operations, each node's weight ww is between 30000-30000 and 3000030000.