atcoder#ABC187E. [ABC187E] Through Path
[ABC187E] Through Path
Score : points
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.
5
1 2
2 3
2 4
4 5
4
1 1 1
1 4 10
2 1 100
2 2 1000
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 .
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
72
8
13
26
58
72
5
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
1657
1657
2109
1703
1474
1657
3202
1474
1247
2109
2559