295 传统题

[ABC368D] 最小包含子虚树 (Minimum Steiner Tree)

时间限制
2000ms
内存限制
256MiB
登顶 / 尝试
0/ 0
难度
4

[ABC368D] 最小包含子虚树 (Minimum Steiner Tree)

Problem Statement

You are given a tree with NN vertices numbered 11 to NN. The ii-th edge connects vertices AiA_i and BiB_i.

Consider a tree that can be obtained by removing some (possibly zero) edges and vertices from this graph. Find the minimum number of vertices in such a tree that includes all of KK specified vertices V1,…,VKV_1,\ldots,V_K.

Input

The input is given from Standard Input in the following format:

$N$ $K$
$A_1$ $B_1$
$\vdots$
$A_{N-1}$ $B_{N-1}$
$V_1$ $\ldots$ $V_K$

Output

Print the answer.

Example

7 3
1 2
1 3
2 4
2 5
3 6
3 7
1 3 5
4

Note

  • Constraints:

  • 1≤K≤N≤2×1051 \leq K \leq N \leq 2\times 10^5

  • 1≤Ai,Bi≤N1 \leq A_i,B_i \leq N

  • 1≤V1<V2<…<VK≤N1 \leq V_1 < V_2 < \ldots < V_K \leq N

  • The given graph is a tree.

  • All input values are integers.

  • Source: ABC368D