#abc187e. E - Through Path
E - Through Path
Score : points
问题陈述
我们有一棵有 个顶点和 条边的树,顶点编号为 ,边编号为 。第 条边连接顶点 和 。 树中的每个顶点上都写有一个整数。设 为写在顶点 上的整数。最初,。
您将获得 个查询。第 个查询由整数 、 和 组成,如下:
- 如果 :对于从顶点 出发,不经过顶点 通过遍历边可达的每个顶点 ,将 替换为 。
- 如果 :对于从顶点 出发,不经过顶点 通过遍历边可达的每个顶点 ,将 替换为 。
处理完所有查询后,打印每个顶点上写的整数。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
We have a tree with vertices and edges, where the vertices are numbered and the edges are numbered . Edge connects Vertices and .
Each vertex in the tree has an integer written on it. Let be the integer written on Vertex . Initially, .
You will be given queries. The -th query, consisting of integers , , and , is as follows:
- If : for each Vertex reachable from Vertex without visiting Vertex by traversing edges, replace with .
- If : for each Vertex reachable from Vertex without visiting Vertex by traversing edges, replace with .
After processing all queries, print the integer written on each vertex.
Constraints
- All values in input are integers.
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
Print the values 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 to each vertex reachable from Vertex without visiting Vertex , that is, Vertex .
In the second query, we add to each vertex reachable from Vertex without visiting Vertex , that is, Vertex .
In the third query, we add to each vertex reachable from Vertex without visiting Vertex , that is, Vertex .
In the fourth query, we add to each vertex reachable from Vertex without visiting Vertex , that is, Vertex .
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