QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100 可 Hack ✓

#9996. Lexicographical Order

统计

You are given an unrooted tree with $n$ nodes, where $k$ nodes are initially black and the remaining nodes are gray. You can choose to color some gray nodes white at the beginning. After coloring, the following process is repeated until no gray nodes remain in the tree.

In each round, the following operations are performed simultaneously for all gray nodes:

  1. Check if any node directly connected to the gray node $u$ is black or white. If not, $u$ remains gray.
  2. If any node directly connected to $u$ is white, $u$ becomes white.
  3. If any node directly connected to $u$ is black, $u$ becomes black.

This order implies that if a node is adjacent to both white and black nodes, it will be colored white.

Note that the operations are performed on all gray nodes simultaneously, meaning that nodes colored in the current round cannot serve as the basis for changing the color of other nodes in the same round.

Find the minimum number of nodes that need to be colored white initially so that the final number of black nodes in the tree does not exceed $k$.

Input

The first line contains two integers $n$ and $k$ ($1 \le n \le 10^6, 1 \le k \le n$), as described above.

The second line contains $k$ integers, representing the indices of the nodes that are initially black.

The next $n-1$ lines each contain two integers $u$ and $v$ ($1 \le u, v \le n$), representing an edge in the tree.

Output

Output a single integer, the answer.

Examples

Input 1

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

Output 1

1

Input 2

(See ex_2.in in the download directory)

Output 2

(See ex_2.ans in the download directory)

Note

  • For the first example, coloring node $2$ white initially is sufficient.
  • For the second example, coloring nodes $3, 4, 9$ white initially is one of the sets with the minimum number of nodes that satisfies the condition.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.