切断与累加AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)There is a tree with $N$ vertices numbered $1,2,\dots,N$. Here, $N$ is odd.
The edges are also numbered $1,2,\dots,N-1$, and edge $i$ connects vertices $A_i$ and $B_i$.
有一棵包含 $N$ 个顶点的树,顶点编号为 $1,2,\dots,N$。其中,$N$ 为奇数。
边的编号为 $1,2,\dots,N-1$,边 $i$ 连接顶点 $A_i$ 和 $B_i$。AI (CI翻译)
Each vertex $i$ has a variable $x_i$, and initially $x_i=0$ for every vertex $i$.
每个顶点 $i$ 都有一个变量 $x_i$,初始时,所有顶点 $i$ 的变量均满足 $x_i=0$。AI (CI翻译)
Now, for $i=1,2,\dots,N-1$ in this order, perform the following operation.
现在,按照 $i=1,2,\dots,N-1$ 的顺序执行以下操作。AI (CI翻译)
- First, remove edge
$i$. As a result, the tree is split into two connected components. - For every vertex
$v$in the connected component containing more vertices, add$i$to$x_v$. - Since
$N$is odd, the connected component containing more vertices is uniquely determined. - Finally, restore edge
$i$.
- 首先,删除边
$i$。此时,树被分成两个连通分量。 - 对于顶点数较多的连通分量中的每个顶点
$v$,将$x_v$加上$i$。 - 由于
$N$为奇数,顶点数较多的连通分量可以唯一确定。 - 最后,恢复边
$i$。
Find the values of the variables $x_1,x_2,\dots,x_N$ of the vertices after all operations are performed.
求所有操作完成后,各顶点的变量 $x_1,x_2,\dots,x_N$ 的值。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)- All input values are integers.
$N$is an odd number satisfying$3 \le N \le 2 \times 10^5 - 1$.$1 \le A_i < B_i \le N$- The given graph is a tree.
- 所有输入值均为整数。
$N$为奇数,且满足$3 \le N \le 2 \times 10^5 - 1$。$1 \le A_i < B_i \le N$- 给定的图是一棵树。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入通过标准输入以如下格式给出:AI (CI翻译)
N
A_1 B_1
A_2 B_2
\vdots
A_{N-1} B_{N-1}
N
A_1 B_1
A_2 B_2
\vdots
A_{N-1} B_{N-1}AI (CI翻译)
Output
输出格式
AI (CI翻译)Output the final values of the variables in the following format:
按如下格式输出各变量的最终值:AI (CI翻译)
x_1 x_2 \dots x_N
x_1 x_2 \dots x_NAI (CI翻译)
样例
5
2 4
1 5
1 4
1 3
10 6 6 7 8
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
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。