#P7276. 送给好友的礼物

送给好友的礼物

Description

Given a tree TT with nn nodes, the nodes are numbered from 11 to nn.

At time 00, both M and B are at node 11. At the beginning of each time step starting from time 11, 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 kk strawberries on the tree, located on kk 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 11.

Input Format

The first line contains two integers n,kn, k (1kn4151 \leq k \leq n \leq 415), representing the number of nodes in the tree and the number of strawberries.
The next n1n - 1 lines each contain two integers uu and vv, indicating that there is an edge between uu and vv in the tree.
The next line contains kk distinct integers a1,a2,,aka_1, a_2, \ldots , a_k, representing the nodes where the kk 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: 12324211 \to 2 \to 3 \to 2 \to 4 \to 2 \to 1.

B's route is: 15676511 \to 5 \to 6 \to 7 \to 6 \to 5 \to 1.


[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (66 points): n3n \leq 3.
  • Subtask 2 (11 point): k=1k = 1.
  • Subtask 3 (1111 points): n7n \leq 7.
  • Subtask 4 (1717 points): k20k \leq 20.
  • Subtask 5 (4242 points): n90n \leq 90.
  • Subtask 6 (2323 points): no special constraints.

For 100%100\% of the testdata, 1kn4151 \leq k \leq n \leq 415, 1u,vn1 \leq u, v \leq n.

Translated by ChatGPT 5