#abc187e. E - Through Path

E - Through Path

Score : 500500 points

问题陈述

我们有一棵有 NN 个顶点和 N1N-1 条边的树,顶点编号为 1,2,,N1, 2, \dots, N,边编号为 1,2,,N11, 2, \dots, N-1。第 ii 条边连接顶点 aia_ibib_i。 树中的每个顶点上都写有一个整数。设 cic_i 为写在顶点 ii 上的整数。最初,ci=0c_i = 0

您将获得 QQ 个查询。第 ii 个查询由整数 tit_ieie_ixix_i 组成,如下:

  • 如果 ti=1t_i = 1:对于从顶点 aeia_{e_i} 出发,不经过顶点 beib_{e_i} 通过遍历边可达的每个顶点 vv,将 cvc_v 替换为 cv+xic_v + x_i
  • 如果 ti=2t_i = 2:对于从顶点 beib_{e_i} 出发,不经过顶点 aeia_{e_i} 通过遍历边可达的每个顶点 vv,将 cvc_v 替换为 cv+xic_v + x_i

处理完所有查询后,打印每个顶点上写的整数。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

We have a tree with NN vertices and N1N-1 edges, where the vertices are numbered 1,2,,N1, 2, \dots, N and the edges are numbered 1,2,,N11, 2, \dots, N-1. Edge ii connects Vertices aia_i and bib_i.
Each vertex in the tree has an integer written on it. Let cic_i be the integer written on Vertex ii. Initially, ci=0c_i = 0.

You will be given QQ queries. The ii-th query, consisting of integers tit_i, eie_i, and xix_i, is as follows:

  • If ti=1t_i = 1: for each Vertex vv reachable from Vertex aeia_{e_i} without visiting Vertex beib_{e_i} by traversing edges, replace cvc_v with cv+xic_v + x_i.
  • If ti=2t_i = 2: for each Vertex vv reachable from Vertex beib_{e_i} without visiting Vertex aeia_{e_i} by traversing edges, replace cvc_v with cv+xic_v + x_i.

After processing all queries, print the integer written on each vertex.

Constraints

  • All values in input are integers.
  • 2N2×1052 \le N \le 2 \times 10^5
  • 1ai,biN1 \le a_i, b_i \le N
  • The given graph is a tree.
  • 1Q2×1051 \le Q \le 2 \times 10^5
  • ti{1,2}t_i \in \{1, 2\}
  • 1eiN11 \le e_i \le N-1
  • 1xi1091 \le x_i \le 10^9

Input

Input is given from Standard Input in the following format:

NN

a1a_1 b1b_1

\vdots

aN1a_{N-1} bN1b_{N-1}

QQ

t1t_1 e1e_1 x1x_1

\vdots

tQt_Q eQe_Q xQx_Q

Output

Print the values c1,c2,,cNc_1, c_2, \dots, c_N after processing all queries, each in its own line.

Sample Input 1

5
1 2
2 3
2 4
4 5
4
1 1 1
1 4 10
2 1 100
2 2 1000

Sample Output 1

11
110
1110
110
100

In the first query, we add 11 to each vertex reachable from Vertex 11 without visiting Vertex 22, that is, Vertex 11.
In the second query, we add 1010 to each vertex reachable from Vertex 44 without visiting Vertex 55, that is, Vertex 1,2,3,41, 2, 3, 4.
In the third query, we add 100100 to each vertex reachable from Vertex 22 without visiting Vertex 11, that is, Vertex 2,3,4,52, 3, 4, 5.
In the fourth query, we add 10001000 to each vertex reachable from Vertex 33 without visiting Vertex 22, that is, Vertex 33.

Sample Input 2

7
2 1
2 3
4 2
4 5
6 1
3 7
7
2 2 1
1 3 2
2 2 4
1 6 8
1 3 16
2 4 32
2 1 64

Sample Output 2

72
8
13
26
58
72
5

Sample Input 3

11
2 1
1 3
3 4
5 2
1 6
1 7
5 8
3 9
3 10
11 4
10
2 6 688
1 10 856
1 8 680
1 8 182
2 2 452
2 4 183
2 6 518
1 3 612
2 6 339
2 3 206

Sample Output 3

1657
1657
2109
1703
1474
1657
3202
1474
1247
2109
2559