Time limit: 1 second Memory limit: 256 MB On Floki Island k k different tribes are…
- User
Time limit: 1 second Memory limit: 256 MB On Floki Island k k different tribes are located in k They live in different places. The map of Floki Island is in the form of a connected graph that has n n place (top) and n
1 n−1 is the road (edge).
Due to the differences of opinion that occurred between the tribes of this island during this period, the process of their civil wars has started; Every day, each of the tribes infiltrates all the places adjacent to their road and takes possession of that place. If two tribes reach a common place or one of the tribes reaches a place that is already occupied by another tribe, these two tribes negotiate with each other and as a result unite together and henceforth act as one. They act as a single clan (maybe even more than two clans are united at the same time!).
As a spy of the World Peace Organization, you are tasked with the help of the Floki Island graph that is given to you at the entrance, the first day of the war that all this k Find k clans that unite with each other during their civil war.
input In the first line of input number n n and k k, which are equal to the number of places and tribes of the island, respectively.
1 ≤ n ≤ 1 0 6 1≤n≤10 6
in each of n
1 n−1 next line of two numbers u i u i and v i v i It is said that it represents the two ends of the mane i i is the island graph. then k k different numbers are given in one line, which number a i a i The primary head of the tribe i i is the input in the graph. It is guaranteed that the input graph meets the necessary conditions and is valid.
1 ≤ k , a i ≤ n 1≤k,a i ≤n
output Print the minimum number of days it takes for all clans to unite and agree on a single output line.
examples Sample entry 1 5 3 1 2 1 3 1 4 1 5 2 3 4 Plain text Sample output 1 1 Plain text Sample input 2 4 2 1 2 2 3 3 4 1 4 Plain text Sample output 2 2 Plain text Sample entry 3 8 3 1 2 2 3 3 4 4 5 5 6 3 7 7 8 2 6 8 Plain text Sample output 3 2 write in c++
- Assistant