#P10421. Sum of Path Lengths in a Tree
Sum of Path Lengths in a Tree
Sum of Path Lengths in a Tree
Given a tree with n nodes, where each edge has a length of 1, compute the sum of the lengths of all paths whose lengths lie in the range \(L\) to \(R\) (inclusive). Two paths are considered identical if they traverse the exact same set of edges.
Formally, you are required to determine the value of $$ \sum_{i=1}^{n} \sum_{j=i+1}^{n} \Bigl(dis(i,j) \cdot [L \le dis(i,j) \le R]\Bigr), $$ where \(dis(i,j)\) denotes the distance between nodes \(i\) and \(j\), and \([C]\) equals 1 if the condition \(C\) is true and 0 otherwise.
inputFormat
The first line contains three integers: n, \(L\), and \(R\). Each of the following \(n-1\) lines contains two integers \(u\) and \(v\), which represent an edge between nodes \(u\) and \(v\).
outputFormat
Output a single integer representing the sum of the lengths of all paths whose lengths are between \(L\) and \(R\) (inclusive).
sample
5 2 3
1 2
2 3
3 4
3 5
8