#P8917. [DMOI-R2] 风神瞳(Anemoculus)
[DMOI-R2] 风神瞳(Anemoculus)
Background

Problem Description
In Windrise, there is a big tree with nodes, rooted at node .
There are Anemoculi on the tree. The -th Anemoculus is located at node .
You want to collect these Anemoculi, so you ask Venti for help (who is slacking off by the big tree).
At the beginning, you are at the root of the tree, i.e. node . Each second, you can move from the current node to an adjacent node. Alternatively, you can ask Venti for help: he will create a wind current, and you can use it to move upward exactly steps in one go. (We define the direction from the root to the leaves as “up”, i.e. from a node with smaller depth to a node with larger depth. In other words, you can move from the current node toward greater depth for consecutive steps.) When you reach a node that has an Anemoculus, you can collect the Anemoculus at that node, and collecting takes no time. Since you would get hurt if you jump down from the tree, you must return to the root in the end. Now you have queries. For the -th query, you are asked: within seconds, what is the maximum number of Anemoculi you can collect?
Input Format
The first line contains four positive integers , with meanings as described above.
The next lines each contain two positive integers , indicating that nodes and are adjacent.
The next line contains pairwise distinct positive integers. The -th number is , with meaning as described above.
The next lines each contain one positive integer , with meaning as described above.
Output Format
For each of the queries, output one line, indicating the maximum number of Anemoculi that can be collected.
8 3 1 6
1 2
1 3
1 6
2 4
2 5
3 7
3 8
6 7 8
1
3
5
6
7
8
0
1
1
2
2
3
8 3 2 6
1 2
1 3
1 6
2 4
2 5
3 7
3 8
6 7 8
1
3
5
6
7
8
0
1
2
2
3
3
Hint
Sample Explanation
Sample 1

As shown, the bold nodes are those with Anemoculi. Venti is very lazy is busy and will not help you.
Sample 2
This sample is the same as Sample 1, except that Venti allows you to move upward by two steps at once.
Constraints
This problem uses bundled testdata.
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, , , , , , , where is the depth of the tree, and the depth of the root is defined as .
Translated by ChatGPT 5