F.A.Qs Home ProblemSet Status Ranklist Contest LoginRegister 捐赠本站
Notice:开心刷题:)
Problem 3639. -- Query on a tree VII -- 衡阳八中OJ离线版-2014-11-04

3639: Query on a tree VII

Time Limit: 10 Sec  Memory Limit: 512 MB
Submit: 39  Solved: 20
[Submit][Status]

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:

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.

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

Sample Output

1
5

HINT

Source

By xiaodao

[Submit][Status]

HOME Back