12401240 SUSTech Online Judge
Problem 1240 --K people travel on a tree

1240: K people travel on a tree

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 269  Solved: 62
[Submit][Status][Web Board]

Description

There are N cities numbered from 1 to N and N-1 roads connecting these N cities, or consider it is a tree with N nodes. Each road takes 1 day to travel through. There are K people initially stays at different K cities. They decide to meet at the same city as soon as possible.  Please find the minimal time needed.

Input

The first line will be an integer \(T (1 \leq T \leq 10)\), which is the number of test cases.   
For each test data: 
The first line contains two integers \(N (1 \leq N \leq 10^5)\) and \(K (1 \leq K \leq N)\) — the number of cities and the number of friends. 
The next N - 1 lines contain two integers A and B, which means there is a road between city A and city B.
Then the next one line contains K  integers, the i-th integer \(p_i\) indicates the place they initially stay.

Output

For each case, contains one line,  print the minimal time.

Sample Input

1
4 2
1 2
2 4
2 3
1 3

Sample Output

1

HINT

Source

 

[Submit][Status]