
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Start DFS from each leaf node. stop the DFS when the number of steps done > distance.
If you reach another leaf node within distance steps, add 1 to the answer.
Note that all pairs will be counted twice so divide the answer by 2.