#P15407. [NOISG 2026 Prelim] 米浴的数据结构课(民间数据)

    ID: 19624 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>线段树倍增二分树链剖分2026NOISG(新加坡)树的重心

[NOISG 2026 Prelim] 米浴的数据结构课(民间数据)

Problem Description

Miyu is taking a data structures class.

In the class, she learned about the weighted centroid of a tree.

The weighted centroid of a tree is defined as follows:

Let ai(ai≥1)a_i (a_i \ge 1) denote the weight of node ii. A node uu is a centroid of the tree if and only if, after deleting node uu, for every remaining connected component, the sum of weights in that component is ≤12∑ai\le \frac{1}{2} \sum a_i.

Now she has a tree with nn nodes, rooted at node 1, and the node weight of node ii is aia_i.

She wants to find the weighted centroid of this tree, but that is too easy. So she adds qq operations for herself, and each operation is one of the following two types:

  • 1 u v w1\ u\ v\ w: Increase the node weights of all nodes on the path from uu to vv by ww.
  • 2 u w2\ u\ w: Increase the node weights of all nodes in the subtree of uu by ww.

After each operation, she wants to find all weighted centroids of the tree. If there are multiple, output them in increasing order of node indices.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer T(1≤T≤10000)T (1 \le T \le 10000), denoting the number of test cases.

For each test case, the first line contains two integers n,q(1≤n,q≤105)n, q (1 \le n, q \le 10^5).

The next line contains nn integers a1,a2,…,an(1≤ai≤108)a_1, a_2, \ldots, a_n (1 \le a_i \le 10^8).

The next n−1n - 1 lines each contain two integers ui,viu_i, v_i, denoting an edge in the tree.

The next qq lines describe the operations. In the ii-th line, the first integer is opi∈{1,2}op_i \in \{1, 2\}.

  • If opi=1op_i = 1, then three integers u,v,w(1≤u,v≤n,w≤108)u, v, w (1 \le u, v \le n, w \le 10^8) follow.
  • If opi=2op_i = 2, then two integers u,w(1≤u≤n,w≤108)u, w (1 \le u \le n, w \le 10^8) follow.

It is guaranteed that ∑n,∑q≤105\sum n, \sum q \le 10^5, and the input graph is a tree.

Output Format

For each test case, output qq lines. In the ii-th line, output some integers, which are all weighted centroids of the tree after the ii-th operation, sorted in increasing order of node indices.

1
5 3
1 1 1 1 1
1 2
1 3
3 4
3 5
1 1 1 1
1 1 1 1
2 3 5
1 3
1
3

Hint

Subtasks

For 100% of the testdata, it holds that

$1 \le T \le 10000, 1 \le \sum n, \sum q \le 10^5, 1 \le a_i, w \le 10^8$

Subtask ID Constraints Points
1 ∑n,∑q≤1000\sum n, \sum q \le 1000 20
2 The tree is a chain 10
3 The tree is a star
4 Both the tree shape and the operations are generated uniformly at random 20
5 No additional constraints 40

Translated by ChatGPT 5