#P9864. [POI 2021/2022 R2] age

[POI 2021/2022 R2] age

Background

Translated from POI2021~2022R2 Day1T1

Problem Description

There is a country with nn cities. We can view it as a tree with n1n-1 roads. One day, you suddenly decide to place kk people in different cities. The people and their movement must satisfy the following rules:

  • Each day, only one person may move, and they can move to a neighboring city connected by a road.

  • Suppose there are two people a,ba,b. If city ii has been visited by aa, then bb is not allowed to visit city ii.

Initially, you know the positions of the people. Each person starts in a different city, and that city is considered “already visited”. You need to plan a valid visiting scheme.

Find the minimum number of days needed so that all cities are visited by someone.

Input Format

The first line contains two integers $n,k\ (1 \leq n \leq 5 \times 10^5, 1 \leq k \leq n)$。

The second line contains kk integers, representing the initial positions of the people.

Then follow n1n-1 lines, each describing a road (ai,bi) (1ai,bin)(a_i,b_i)\ (1 \leq a_i,b_i \leq n)

Output Format

Output the minimum number of days。

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

Hint

Explanation of the sample:

The subtasks are as follows:

Subtask ID Special property Score
11 n10n \leq 10 66
22 n20n \leq 20 1313
33 n2000n \leq 2000 2727
44 k=1k=1 1010
55 k=2k=2 77
66 The input is a chain
77 No special property 3030

Subtask 00 is the sample。

Translated by ChatGPT 5