luogu#P16338. 「ALFR Round 10」纸牌
「ALFR Round 10」纸牌
Problem Description
There are players playing a certain card game, numbered from to . The players form a tree structure. Player initially has cards and energy points. You are player .
At the beginning of the game, everyone agrees on an integer . Then player chooses a permutation , such that is a DFS order of the original tree when rooted at .
Initially, let . Then for each in order, player must choose exactly one of the following actions:
-
Discard some cards from their hand. The number of discarded cards must be at most , and must be at least the number discarded by the previous player who chose to discard, plus .
Formally, choose an integer such that , and set .
In particular, if , then this action cannot be chosen. -
Lose energy points.
Formally, set .
Once a player's remaining energy becomes , they are eliminated.
You win if and only if after the entire process ends, you are not eliminated, regardless of whether other players are eliminated.
You want to know how many integers with satisfy the following:
There exists some strategy of the other players (excluding you), such that no matter what you do, you will inevitably lose.
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , denoting the number of test cases.
For each test case:
The first line contains two positive integers , representing the number of nodes in the tree and your player index.
The next lines each contain two integers .
The next lines each contain two integers , indicating that there is an edge between nodes and in the tree.
Output Format
For each test case, output one line containing one integer: the required answer.
1
5 1
1 2
2 2
1 1
3 2
4 2
1 2
1 3
3 4
3 5
4
1
5 3
2 3
3 3
1 6
6 2
8 6
1 2
1 3
3 4
4 5
0
Hint
Explanation of Sample 1
When , there exists an optimal strategy for the opponents that guarantees your failure.
For example, when , one possible DFS order rooted at is . Following this order:
- Player chooses to lose energy points.
- Player chooses to discard cards.
Then you (player ) must discard at least cards, but , so you cannot choose the discard action. You are forced to lose energy points and are eliminated immediately. Therefore, you lose.
Explanation of Sample 2
Since , no matter what strategy the opponents use, you can always choose to lose energy points without being eliminated. Therefore, you are guaranteed to win.
Constraints
This problem uses bundled subtasks.
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| None | |||
| None |
Special property : it is guaranteed that .
Special property : the tree is generated as follows: after fixing , for each , an integer is chosen uniformly at random from , and an edge is added between and .
Special property : it is guaranteed that .
For all test cases, it is guaranteed that , , , , .