F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Query on a tree VII

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 334    Accepted Submission(s): 73


Problem Description
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
Multicase.
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.
 

Sample Input
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 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
 

Sample Output
1 5 7 5 7
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-05 08:57:42, Gzip enabled