#P15875. [ICPC 2026 NAC] Acorn Quarrels
[ICPC 2026 NAC] Acorn Quarrels
Description
There are squirrels storing acorns in a tree. The (botanical) oak tree is also a graph-theoretic tree: a connected graph with vertices labeled from to and undirected edges. Each squirrel sits at a different vertex of the tree and two squirrels are if their vertices share an edge.
In ascending order of vertex label starting with the squirrel at vertex , each squirrel steals one acorn from the neighboring squirrel that currently has the most acorns. If multiple neighbors are tied for having the most acorns, the squirrel steals one acorn from each of them!
To limit the fallout of these shenanigans, you want to distribute acorns to the squirrels so that each squirrel begins with at least acorns (so that no squirrel runs out of acorns due to thefts) and ends with the same number of acorns after all squirrels are done stealing from each other as they had originally. It can be shown that such a distribution exists where every squirrel begins with at most acorns. Find any distribution satisfying these conditions.
Input Format
The first line of input contains an integer , the number of vertices (and squirrels).
Each of the following lines contains two space-separated integers and , indicating that an edge exists between vertices and . There is at most one edge between any pair of vertices, and the edges form a tree.
Output Format
Print space-separated integers satisfying , where is the number of acorns you would like to distribute to the squirrel at vertex . Your solution will be accepted if every squirrel ends with the same number of acorns as they started with after all thefts have occurred. It can be proved that such a distribution of acorns always exists.
5
1 2
1 3
1 4
2 5
6 5 7 7 9
8
5 4
3 7
8 4
4 7
5 2
1 3
6 4
14 15 10 9 13 14 14 14
京公网安备 11011102002149号