#abc368d. D - Minimum Steiner Tree
D - Minimum Steiner Tree
Score : points
问题陈述
你得到了一个有 个顶点的树,顶点编号从 到 。第 条边连接顶点 和 。
考虑一个可以通过从这个图中移除一些(可能为零)边和顶点得到的树。找出包含所有指定的 个顶点 的这样的树中顶点的最小数量。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a tree with vertices numbered to . The -th edge connects vertices and .
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 specified vertices .
Constraints
- The given graph is a tree.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
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 is shown on the right.
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