#P3639. QTREE7 - Query on a tree VII

QTREE7 - Query on a tree VII

QTREE7 - Query on a tree VII

题面翻译

一棵树,每个点初始有个点权和颜色。

0 u :询问所有 u,vu,v 路径上的最大点权,要满足 u,vu,v 路径上所有点的颜色都相同。

1 u :反转 uu 的颜色。

2 u w :把 uu 的点权改成 ww

colori[0,1]color_i\in[0,1]wi[109,109]w_i\in[-10^9,10^9]n,m105n,m\le10^5

感谢@Kelin 提供的翻译

题目描述

You are given a tree (an acyclic undirected connected graph) with nn nodes. The tree nodes are numbered from 11 to nn. 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 uu, two nodes are connected if all the node on the path from uu to vv (inclusive uu and vv) have a same color.
  • 1 u: toggle the color of uu(that is, from black to white, or from white to black).
  • 2 u w: change the weight of uu to ww.

输入格式

The first line contains a number nn denoted how many nodes in the tree(n1n-1 lines), each line has two numbers (u,v)(u, v) describe a edge of the tree(1 u, v 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| m denoted how many operations we are going to process(1 m m lines, each line describe a operation (t, u) as we mentioned above(0 t u n, |w|

输出格式

For each query operation, output the corresponding result.

样例 #1

样例输入 #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

样例输出 #1

1
5

样例 #2

样例输入 #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

样例输出 #2

7
5
7