Problem F: K people travel on a tree

## Problem F: K people travel on a tree

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1455  Solved: 270
[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

[Submit][Status]
{"ft_lang_label":"__label__en","ft_lang_prob":0.8905315,"math_prob":0.9934475,"size":1107,"snap":"2022-40-2023-06","text_gpt3_token_len":314,"char_repetition_ratio":0.10788758,"word_repetition_ratio":0.028301887,"special_character_ratio":0.28635952,"punctuation_ratio":0.09465021,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9654943,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-01T05:28:35Z\",\"WARC-Record-ID\":\"<urn:uuid:7627d8a9-2b83-442f-a3d6-9f1872f4bf27>\",\"Content-Length\":\"9446\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1a060a87-db5d-49d6-8d9f-844e32618a11>\",\"WARC-Concurrent-To\":\"<urn:uuid:dd1e6788-dac8-4488-a9aa-de9d2385b72e>\",\"WARC-IP-Address\":\"116.7.234.143\",\"WARC-Target-URI\":\"https://acm.sustech.edu.cn/onlinejudge/problem.php?cid=1085&pid=5\",\"WARC-Payload-Digest\":\"sha1:NAMFYFM7QGFCCF737JUCEG6LMWKFE3TU\",\"WARC-Block-Digest\":\"sha1:D7INAG5YS5562PUUVSYJ3LWIF3RMLEGG\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764499911.86_warc_CC-MAIN-20230201045500-20230201075500-00667.warc.gz\"}"}