Submit | All submissions | Best solutions | Back to list |
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 ≤ 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 ≤ u ≤ n, |w| ≤ 109).
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
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 |
hide comments
2022-08-22 06:16:07 [Rampage] Blue.Mary
After solving this I have finished all SPOJ classical problems with solvers >= 100. Last edit: 2022-08-22 06:16:17 |
|
2014-07-03 18:59:38 xiaodao
@(test) O10^5 as well .. fixed. |
|
2014-07-03 18:59:38 (test)
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. :) |
|
2014-07-03 18:59:38 xiaodao
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 |
|
2014-07-03 18:59:38 (test)
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. |