#P8981. 「DROI」Round 1 距离
「DROI」Round 1 距离
Background
No distance is impossible to cross.
Problem Description
Given a tree , define the distance between two nodes as the number of nodes on the path between them.
If for two nodes on the tree, the following holds: $\forall x \in G,\operatorname{dis}(u,x) \leq \operatorname{dis}(u,v)$ and $\operatorname{dis}(v,x) \leq \operatorname{dis}(u,v)$, then we call the unordered pair an extremely far pair.
Also, for a node in the tree , its weight is defined as: the number of extremely far pairs whose shortest path passes through .
Given the tree , compute , where is a given constant and .
Input Format
The first line contains two integers , representing the number of nodes in the tree and the given constant.
The next lines each contain two integers , indicating that there is an edge between node and node .
Output Format
Output one integer in one line, representing the answer.
2 1
1 2
2
5 2
1 2
1 3
4 1
5 1
72
Hint
Sample Explanation #1
is an extremely far pair, so the weights of nodes and are both , and .
Sample Explanation #2
The extremely far pairs are , so the answer is .
Constraints
| Test Point ID | ||||||||
|---|---|---|---|---|---|---|---|---|
For of the testdata, and .
The input size is large, so please use a fast input method.
Translated by ChatGPT 5