P5908 Cats and Penguins
Description
There are $n$ residential areas in the kingdom. They are connected by $n - 1$ roads, and it is guaranteed that from any residential area you can reach any other one. The length of each road is $1$.
In every residential area except area $1$, there lives a little penguin. One day, a cat starts from residential area $1$ and wants to visit some penguins. However, the cat is very lazy and is only willing to visit penguins whose distance from it is at most $d$.
Please tell the cat how many penguins it can visit.
Input Format
The first line contains two integers $n, d$, with the meanings as described above.
Starting from the second line, there are $n - 1$ lines. Each line contains two integers $u, v$, indicating that there is a road between residential areas $u$ and $v$.
Output Format
Output one integer in a single line, indicating how many penguins the cat can visit.
Explanation/Hint
For $100\%$ of the testdata, $1 \le n, d \le 10^5$. It is guaranteed that all residential areas are numbered starting from $1$.
Translated by ChatGPT 5