#P6626. [省选联考 2020 B 卷] 消息传递
[省选联考 2020 B 卷] 消息传递
Description
Given a tree-shaped social network with people (numbered from to ). If a person receives a message on some day, then on the next day they will pass the message to all people who have a direct social relationship with them.
Now there are queries. In each query, assume that person receives a message on day . Please compute how many people newly receive this message on day (that is, people who have received this message before day are not counted). Different queries do not affect each other.
Input Format
This problem contains multiple sets of testdata.
The first line contains an integer , the number of test cases.
For each test case:
The first line contains two integers , representing the number of people in the tree-shaped social network and the number of queries.
The next lines each contain two integers , indicating that there is a direct social relationship between person and person . It is guaranteed that the input forms a tree-shaped social network.
The next lines each contain two integers , as described in the statement.
Output Format
For each test case, output lines, each containing one integer representing the answer to the query.
1
4 2
1 2
2 3
3 4
1 1
2 2
1
1
Hint
Sample Explanation
For the first query, the only person who newly receives the message on day is person . For the second query, the people who newly receive the message on day are persons and , and the person who newly receives the message on day is person .
Constraints and Notes
For test point : .
For test point : .
For test point : .
For test points : .
For test points : .
For all test points: .
Translated by ChatGPT 5
京公网安备 11011102002149号