|
||||||||||
Park VisitTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6269 Accepted Submission(s): 2622 Problem Description Claire and her little friend, ykwd, are travelling in Shevchenko's Park! The park is beautiful - but large, indeed. N feature spots in the park are connected by exactly (N-1) undirected paths, and Claire is too tired to visit all of them. After consideration, she decides to visit only K spots among them. She takes out a map of the park, and luckily, finds that there're entrances at each feature spot! Claire wants to choose an entrance, and find a way of visit to minimize the distance she has to walk. For convenience, we can assume the length of all paths are 1. Claire is too tired. Can you help her? Input An integer T(T¡Ü20) will exist in the first line of input, indicating the number of test cases. Each test case begins with two integers N and M(1¡ÜN,M¡Ü105), which respectively denotes the number of nodes and queries. The following (N-1) lines, each with a pair of integers (u,v), describe the tree edges. The following M lines, each with an integer K(1¡ÜK¡ÜN), describe the queries. The nodes are labeled from 1 to N. Output For each query, output the minimum walking distance, one per line. Sample Input
Sample Output
Source | ||||||||||
|