100 atcoder#ABC138D. [ABC138D] Ki
[ABC138D] Ki
Score : points
Problem Statement
Given is a rooted tree with vertices numbered to . The root is Vertex , and the -th edge connects Vertex and .
Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value .
Now, the following operations will be performed:
- Operation : Increment by the counter on every vertex contained in the subtree rooted at Vertex .
Find the value of the counter on each vertex after all operations.
Constraints
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the values of the counters on Vertex after all operations, in this order, with spaces in between.
4 3
1 2
2 3
2 4
2 10
1 100
3 1
100 110 111 110
The tree in this input is as follows:
Each operation changes the values of the counters on the vertices as follows:
- Operation : Increment by the counter on every vertex contained in the subtree rooted at Vertex , that is, Vertex . The values of the counters on Vertex are now , respectively.
- Operation : Increment by the counter on every vertex contained in the subtree rooted at Vertex , that is, Vertex . The values of the counters on Vertex are now , respectively.
- Operation : Increment by the counter on every vertex contained in the subtree rooted at Vertex , that is, Vertex . The values of the counters on Vertex are now , respectively.
6 2
1 2
1 3
2 4
3 6
2 5
1 10
1 10
20 20 20 20 20 20