#P9864. Minimum Days to Cover All Cities
Minimum Days to Cover All Cities
Minimum Days to Cover All Cities
A country with n cities is connected by n-1 roads forming a tree. You are given k people located in k distinct cities initially. A city where a person is located at the beginning is considered as visited by that person.
Each day, you are allowed to move exactly one person from its current city to an adjacent city (i.e. two cities sharing a road). However, the following condition must be observed: if a person a has visited a city i at any time, then no other person b is allowed to visit city i in the future.
Your task is to plan a sequence of moves so that eventually every city in the country is visited by someone. Determine the minimum number of days required to accomplish this.
Note that the same person is allowed to revisit a city that he or she has already visited.
Input/Output specifications: See below.
inputFormat
The input begins with a line containing two integers n and k (1 ≤ k ≤ n), representing the number of cities and the number of people respectively.
The second line contains k distinct integers, each in the range [1, n], indicating the starting cities of the k people.
Each of the following n-1 lines contains two integers u and v (1 ≤ u, v ≤ n) which represent a road connecting cities u and v.
It is guaranteed that the given roads form a tree.
outputFormat
Output a single integer — the minimum number of days required so that every city is visited by someone under the given move constraints.
sample
3 1
2
1 2
2 3
3