链接:https://ac.nowcoder.com/acm/problem/202310
来源:牛客网
题目描述
We have met so many problems on the tree, so today we will have a simple problem on a tree.
You are given a tree (an acyclic undirected connected graph) with N\mathbf{N}N nodes. The tree nodes are numbered from 1\mathbf{1}1 to N\mathbf{N}N. Each node has a weight Wi\mathbf{W_i}Wi. We will have four kinds of operations on it and you should solve them efficiently. Wish you have fun!
输入描述:
The first line of the input gives the number of test case, T\mathbf{T}T (1≤T≤101 \leq \mathbf{T} \leq 101≤T≤10). T\mathbf{T}T test cases follow. For each case, the first line contains only one integer N\mathbf{N}N.(1≤N≤100,0001 \leq \mathbf{N} \leq 100,0001≤N≤100,000) The next N−1\mathbf{N-1}N−1 lines each contains two integers x{x}x, y{y}y which means there is an edge between them. It also means we will give you one tree initially. The next line will contains N\mathbf{N}N integers which means the initial weight Wi\mathbf{W_i}Wi of each node. (0≤Wi≤1,000,000,0000 \leq \mathbf{W_i} \leq 1,000,000,0000≤Wi≤1,000,000,000)
The next line will contains an integer Q\mathbf{Q}Q. (1≤Q≤10,0001 \leq \mathbf{Q} \leq 10,0001≤Q≤10,000) The next Q\mathbf{Q}Q lines will start with an integer 1, 2, 3 or 4 means the kind of this operation.
1.Given three integers u{u}u, v{v}v, w{w}w, for the u{u}u, v{v}v and all nodes between the path from u{u}u to v{v}v inclusive, you should update their weight to w{w}w. (1≤u,v≤N1 \leq u, v \leq \mathbf{N}1≤u,v≤N, 0≤w≤1,000,000,0000 \leq w \leq 1,000,000,0000≤w≤1,000,000,000)
2.Given three integers u{u}u, v{v}v, w{w}w, for the u{u}u, v{v}v and all nodes between the path from u{u}u to v{v}v inclusive, you should