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 perform 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 ≤ 10^{5}). The next n1 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 ≤ 10^{9}). The next line contains a number m denoted how many operations we are going to process(1 ≤ m ≤ 10^{5}). The next m lines, each line describe a operation (t, u) as we mentioned above(0 ≤ t ≤ 2, 1 ≤ u ≤ n, w ≤ 10^{9}).
Output
For each query operation, output the corresponding result.
Example
Input 1: 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 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
[Rampage] Blue.Mary:
20220822 06:16:07
After solving this I have finished all SPOJ classical problems with solvers >= 100. Last edit: 20220822 06:16:17 

xiaodao:
20140703 18:59:38
@(test) O10^5 as well .. fixed. 

(test):
20140703 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:
20140703 18:59:38
Thank you for validation.


(test):
20140703 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 (n1) pairs (u, v) do not form a tree. 
Added by:  xiaodao 
Date:  20131018 
Time limit:  1s5s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  Own problem, 2013 MultiUniversity Training Contest 05  Host by HIT 