#P7782. Count Paths Through Each Vertex in a Tree
Count Paths Through Each Vertex in a Tree
Count Paths Through Each Vertex in a Tree
You are given a tree with n vertices and two integer constants L and R. The tree is undirected and connected. A path is defined as the unique simple path between any two distinct vertices. The length of a path is the number of edges it contains.
Your task is to compute, for each vertex u (1 ≤ u ≤ n), the number of paths whose length d satisfies \[ L \le d \le R \] and that pass through vertex u (that is, vertex u lies on the unique simple path connecting the two endpoints, including the case where u is one of the endpoints).
Note: Each path is considered only once (order of endpoints does not matter).
inputFormat
The first line contains three integers: n L R
, where n
is the number of vertices, and L
and R
are the bounds for the path lengths.
Each of the next n-1
lines contains two integers u
and v
(1-based index) indicating that there is an edge between vertices u
and v
.
outputFormat
Output a single line containing n
integers. The i
-th integer is the number of paths (with length between L
and R
inclusive) that pass through vertex i
. The numbers should be separated by spaces.
sample
3 1 2
1 2
2 3
2 3 2