#P16294. [蓝桥杯 2026 省 Java A 组] 子树染色

    ID: 18309 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>动态规划 DP树形 DP2026蓝桥杯省赛

[蓝桥杯 2026 省 Java A 组] 子树染色

Background

.

Problem Description

Given a tree with nn nodes, the nodes are numbered from 11 to nn, where node 11 is the root. Now you need to choose some nodes in this tree to color.

There are mm key nodes in the tree. For each key node xx, let the size of its subtree be ss (the subtree includes xx itself and all of its descendants). Then, in the subtree rooted at xx, the number of colored nodes must be at least s2\lceil \frac{s}{2} \rceil.

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 n+1n + 1 lines.

The first line contains two integers n,mn, m, representing the total number of nodes and the number of key nodes.

The second line contains mm distinct integers, representing the indices of all key nodes.

In the next n1n - 1 lines, each line contains two integers a,ba, b, indicating that there is an edge between node aa and node bb.

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 4,5,7,9,104, 5, 7, 9, 10, for a total of 55 nodes.

Constraints

For 30%30\% of the testdata, 1n2001 \le n \le 200.

For all testdata, 1mn1000001 \le m \le n \le 100000, and 1a,bn1 \le a, b \le n.

Translated by ChatGPT 5