#ABC479E. 切边与累加 / Cut and Add
切边与累加 / Cut and Add
Problem Statement
There is a tree with vertices numbered . Here, is odd.
The edges are also numbered , and edge connects vertices and .
Each vertex has a variable , and initially for every vertex .
Now, for in this order, perform the following operation.
- First, remove edge . As a result, the tree is split into two connected components.
- For every vertex in the connected component containing more vertices, add to .
- Since is odd, the connected component containing more vertices is uniquely determined.
- Finally, restore edge .
Find the values of the variables of the vertices after all operations are performed.
Constraints
- All input values are integers.
- is an odd number satisfying .
- The given graph is a tree.
Input
The input is given from Standard Input in the following format:
Output
Output the final values of the variables in the following format:
5
2 4
1 5
1 4
1 3
10 6 6 7 8
- For , the following operation is performed.
- Removing edge splits the tree into a connected component with vertex and a connected component with vertices .
- The larger one is the connected component with vertices , so is added to all of their variables.
- As a result, the values of the variables become .
- Finally, edge is restored.
- For , the following operation is performed.
- Removing edge splits the tree into a connected component with vertex and a connected component with vertices .
- The larger one is the connected component with vertices , so is added to all of their variables.
- As a result, the values of the variables become .
- Finally, edge is restored.
- For , the following operation is performed.
- Removing edge splits the tree into a connected component with vertices and a connected component with vertices .
- The larger one is the connected component with vertices , so is added to all of their variables.
- As a result, the values of the variables become .
- Finally, edge is restored.
- For , the following operation is performed.
- Removing edge splits the tree into a connected component with vertex and a connected component with vertices .
- The larger one is the connected component with vertices , so is added to all of their variables.
- As a result, the values of the variables become .
- Finally, edge is restored.
The final values of the variables are .
3
1 2
2 3
2 3 1
9
4 6
2 3
1 5
7 8
2 9
5 6
2 6
7 9
20 36 34 28 23 29 23 19 31
- Source: AtCoder ABC 479 E
相关
在下列比赛中: