QTREE7 - Query on a tree VII


You are given a tree (an acyclic undirected connected graph) with n nodes. The tree nodes are numbered from 1 to n. Each node has a color, white or black, and a weight. We will ask you to perfrom some instructions of the following form:

  • 0 u: ask for the maximum weight among the nodes which are connected to u, two nodes are connected if all the node on the path from u to v (inclusive u and v) have a same color.
  • 1 u: toggle the color of u(that is, from black to white, or from white to black).
  • 2 u w: change the weight of u to w.

Input

The first line contains a number n denoted how many nodes in the tree(1 ≤ n ≤ 105). The next n-1 lines, each line has two numbers (u, v) describe a edge of the tree(1 ≤ u, v ≤ n). The next 2 lines, each line contains n number, the first line is the initial color of each node(0 or 1), and the second line is the initial weight, let's say Wi, of each node(|Wi| ≤ 109). The next line contains a number m denoted how many operations we are going to process(1 ≤ m ≤ 105). The next m lines, each line describe a operation (t, u) as we mentioned above(0 ≤ t ≤ 2, 1 ≤ un, |w| ≤ 109).

Output

For each query operation, output the corresponding result.

Example

Input 1:
5
5 1 2 1 3 1 4 1 5 0 1 1 1 1 1 2 3 4 5 3 0 1 1 1 0 1
1 2

Output 1:
1 5

Input 2:
7 1 2 1 3 2 4 2 5 3 6 3 7 0 0 0 0 0 0 0 1 2 3 4 5 6 7 4 0 1 1 1 0 2 0 3

Output 2:

7 5 7


Warning: large input/output data,be careful with certain languages

 

 


hide comments
xiaodao: 2014-07-03 18:59:38

@(test) O10^5 as well .. fixed.

(test): 2014-07-03 18:59:38

Thanks for the quick reply. m should be 10^5 as well? It still shows as 105. This problem now makes more sense as classical, and looks interesting. :)

xiaodao: 2014-07-03 18:59:38

Thank you for validation.
.. Here 109 should be 10^9 .. ..
And 105 should be 10^5 ...
I have submited your validator, it seems OK now ...
Please check it ~

Last edit: 2013-10-20 15:52:21
(test): 2014-07-03 18:59:38

Please correct the test data. For the operation 2 u w, not all the value of |w| are <= 109. In fact, some w < -109. Also, in the test set #14 (or later), the (n-1) pairs (u, v) do not form a tree.


Added by:xiaodao
Date:2013-10-18
Time limit:1s-5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own problem, 2013 Multi-University Training Contest 05 - Host by HIT