#abc368d. D - Minimum Steiner Tree

D - Minimum Steiner Tree

Score : 425425 points

问题陈述

你得到了一个有 NN 个顶点的树,顶点编号从 11NN。第 ii 条边连接顶点 AiA_iBiB_i

考虑一个可以通过从这个图中移除一些(可能为零)边和顶点得到的树。找出包含所有指定的 KK 个顶点 V1,,VKV_1,\ldots,V_K 的这样的树中顶点的最小数量。

以上为大语言模型 kimi 翻译,仅供参考。

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.

Constraints

  • 1KN2×1051 \leq K \leq N \leq 2\times 10^5
  • 1Ai,BiN1 \leq A_i,B_i \leq N
  • 1V1<V2<<VKN1 \leq V_1 < V_2 < \ldots < V_K \leq N
  • The given graph is a tree.
  • All input values are integers.

Input

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

NN KK

A1A_1 B1B_1

\vdots

AN1A_{N-1} BN1B_{N-1}

V1V_1 \ldots VKV_K

Output

Print the answer.

Sample Input 1

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

Sample Output 1

4

The given tree is shown on the left in the figure below. The tree with the minimum number of vertices that includes all of vertices 1,3,51,3,5 is shown on the right.

Figure

Sample Input 2

4 4
3 1
1 4
2 1
1 2 3 4

Sample Output 2

4

Sample Input 3

5 1
1 4
2 3
5 2
1 2
1

Sample Output 3

1