#P6584. 重拳出击
重拳出击
Description
Xiao Z meets Youyou on a tree.
On this tree, the length of every edge is .
At the beginning, Xiao Z is at node , and has a gun with range .
Because Xiao Z is very skilled, each Youyou dies instantly when shot, and Xiao Z will never die.
Xiao Z and the Youyou take turns. In each round, they act in the following order:
-
The round counter (initially ).
-
Xiao Z can use the gun to shoot and kill all Youyou whose distance to Xiao Z on the tree is less than or equal to .
-
If all Youyou have been eliminated, the game ends. The value of the round counter at this time is the number of rounds Xiao Z used.
-
Xiao Z may choose to move along one edge to any adjacent node, or choose to stay.
-
Each Youyou moves one edge along the simple path from itself to Xiao Z. If it is already on the same node as Xiao Z, it does not move.
Xiao Z needs to find the minimum number of rounds required to eliminate all enemies.
Input Format
The first line contains a positive integer .
The next lines each contain two positive integers, representing an edge of the tree.
The next line contains a positive integer .
The next line contains positive integers. The -th number represents the initial node of the -th Youyou.
The last line contains two integers, and Xiao Z’s initial node .
Output Format
Output one positive integer in a single line: the minimum number of rounds.
5
1 2
2 3
3 4
4 5
5
1 2 3 4 5
0 3
3
5
1 2
1 3
2 4
2 5
4
1 1 2 2
1 5
2
Hint
Explanation for Sample 2

In the first round, Xiao Z can shoot and kill the last two Youyou, then move from node to node . The remaining two Youyou will also move to node . In the second round, Xiao Z can eliminate all Youyou. It can be proven that this is the optimal strategy.
Constraints
- Subtask 1 (10 points): .
- Subtask 2 (15 points): .
- Subtask 3 (30 points): .
- Subtask 4 (45 points): .
For all testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号