Trees and Queries 10

Given a tree with vertex weights, answer path maximum-subarray-sum queries and path range-assign-weight updates.

Hard9Segment treeTreeDFSDivide and conquerNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given a tree with NN vertices. A tree is a connected undirected graph with no cycle. The vertices are numbered from 1 to NN, and each vertex carries one integer weight.

Write a program that processes the following two kinds of queries.

  • 1 u v: list the vertices on the path from uu to vv in the order they are visited, then report the largest sum of a contiguous block of that list. The empty block is allowed, so the answer is always at least 0.
  • 2 u v w: change the weight of every vertex on the path from uu to vv to ww.

Exactly one path joins two vertices of a tree, so the path of each query is unique. If uu equals vv, the path is that single vertex.

Input

The first line contains the number of vertices NN (2N100,0002 \le N \le 100{,}000).

The second line contains the weights of vertices 1 through NN in order. Each weight is an integer whose absolute value is at most 10,000.

Each of the next N1N-1 lines contains two vertex numbers uu and vv joined by an edge. The given edges form a tree.

The next line contains the number of queries MM (1M100,0001 \le M \le 100{,}000).

Each of the next MM lines contains one query in the form 1 u v or 2 u v w, where 1u,vN1 \le u, v \le N and ww is an integer whose absolute value is at most 10,000.

Output

For each query of the first kind, print its answer on its own line, in the order the queries are given. A query of the second kind prints nothing.