#P7276. 送给好友的礼物
送给好友的礼物
Description
Given a tree with nodes, the nodes are numbered from to .
At time , both M and B are at node . At the beginning of each time step starting from time , M and B can each choose to either move to a node directly connected to their current node, or stay at their current node.
There are strawberries on the tree, located on different nodes. M and B want to collect all the strawberries. At the end of any time step, if M or B is at a node that has a strawberry, then that strawberry is collected.
They do not want to spend too much time, so you need to answer: at the end of which earliest time step can M and B collect all strawberries and both return to node .
Input Format
The first line contains two integers (), representing the number of nodes in the tree and the number of strawberries.
The next lines each contain two integers and , indicating that there is an edge between and in the tree.
The next line contains distinct integers , representing the nodes where the strawberries are located.
Output Format
Output one integer in one line, the required answer.
7 4
1 2
2 3
2 4
1 5
5 6
6 7
3 4 5 7
6
1 1
1
0
Hint
[Sample Explanation #1]

M's route is: .
B's route is: .
[Constraints]
This problem uses bundled testdata.
- Subtask 1 ( points): .
- Subtask 2 ( point): .
- Subtask 3 ( points): .
- Subtask 4 ( points): .
- Subtask 5 ( points): .
- Subtask 6 ( points): no special constraints.
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号