#P16294. [蓝桥杯 2026 省 Java A 组] 子树染色
[蓝桥杯 2026 省 Java A 组] 子树染色
Background
.
Problem Description
Given a tree with nodes, the nodes are numbered from to , where node is the root. Now you need to choose some nodes in this tree to color.
There are key nodes in the tree. For each key node , let the size of its subtree be (the subtree includes itself and all of its descendants). Then, in the subtree rooted at , the number of colored nodes must be at least .
Please find the minimum number of nodes that need to be colored while satisfying the requirements of all key nodes.
Input Format
The input has a total of lines.
The first line contains two integers , representing the total number of nodes and the number of key nodes.
The second line contains distinct integers, representing the indices of all key nodes.
In the next lines, each line contains two integers , indicating that there is an edge between node and node .
Output Format
Output one integer, representing the minimum total number of nodes that need to be colored.
10 5
3 4 5 7 10
1 2
1 3
1 4
3 5
3 6
3 7
5 8
5 9
6 10
5
Hint
Sample Explanation
One optimal solution is to color nodes , for a total of nodes.
Constraints
For of the testdata, .
For all testdata, , and .
Translated by ChatGPT 5