QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100

#6163. Message Passing

Estadísticas

Given a tree-structured social network containing $n$ people (numbered $1$ to $n$). If a person receives a message on a certain day, they will pass the message to all people with whom they have a direct social relationship on the next day.

There are $m$ queries. For each query, assume person $x$ receives a message on day $0$. Calculate the number of people who receive this message for the first time on day $k$ (i.e., people who had already received the message before day $k$ are not counted). Different queries are independent of each other.

Input

The input contains multiple test cases. The first line contains an integer $T$, the number of test cases.

For each test case:

The first line contains two integers $n$ and $m$, representing the number of people in the tree-structured social network and the number of queries, respectively.

The next $n - 1$ lines each contain two integers $a$ and $b$, indicating that person $a$ and person $b$ have a direct social relationship. It is guaranteed that the input forms a tree.

The next $m$ lines each contain two integers $x$ and $k$, as described in the problem statement.

Output

For each test case, output $m$ lines, each containing a single integer representing the answer to the query.

Examples

Input 1

1
4 2
1 2
2 3
3 4
1 1
2 2

Output 1

1
1

Note 1

For the first query, only person $2$ receives the message for the first time on day $1$.

For the second query, people $1$ and $3$ receive the message for the first time on day $1$, and person $4$ receives the message for the first time on day $2$.

Subtasks

For test case $1$: $1\le n, m\le 10$.

For test case $2$: $1\le n, m\le 100$.

For test case $3$: $1\le n, m\le 1000$.

For test cases $4\sim6$: $1\le n, m\le 10^5, k\le 20$.

For test cases $7\sim10$: $1\le n, m\le 10^5$.

For all test cases: $1\le T\le 5, 1\le x\le n, 0\le k < n$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.