Codeforces Round 328 (Div. 2)
D
Super M
Codeforces
2200
原题
← CE →
翻译中…

Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of $*n*$ cities, connected by $*n* - 1$ bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go from any city to any other city using only the given roads. There are $*m*$ cities being attacked by humans. So Ari... we meant Super M have to immediately go to each of the cities being attacked to scare those bad humans. Super M can pass from one city to another only using the given roads. Moreover, passing through one road takes her exactly one kron - the time unit used in Byteforces.

翻译中…

image

翻译中…

However, Super M is not on Byteforces now - she is attending a training camp located in a nearby country Codeforces. Fortunately, there is a special device in Codeforces that allows her to instantly teleport from Codeforces to any city of Byteforces. The way back is too long, so for the purpose of this problem teleportation is used exactly once.

翻译中…

You are to help Super M, by calculating the city in which she should teleport at the beginning in order to end her job in the minimum time (measured in krons). Also, provide her with this time so she can plan her way back to Codeforces.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*m*$ ($1 ≤ *m* ≤ *n* ≤ 123456$) - the number of cities in Byteforces, and the number of cities being attacked respectively.

翻译中…

Then follow $*n* - 1$ lines, describing the road system. Each line contains two city numbers $*u*_{*i*}$ and $*v*_{*i*}$ ($1 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n*$) - the ends of the road $*i*$.

翻译中…

The last line contains $*m*$ distinct integers - numbers of cities being attacked. These numbers are given in no particular order.

翻译中…

Output

翻译中…

First print the number of the city Super M should teleport to. If there are many possible optimal answers, print the one with the lowest city number.

翻译中…

Then print the minimum possible time needed to scare all humans in cities being attacked, measured in Krons.

翻译中…

Note that the correct answer is always unique.

翻译中…

Note

翻译中…

In the first sample, there are two possibilities to finish the Super M's job in $3$ krons. They are:

翻译中…

image and image.

翻译中…

However, you should choose the first one as it starts in the city with the lower number.

翻译中…

样例

Input #1
7 2
1 2
1 3
1 4
3 5
3 6
3 7
2 7
Output #1
2
3
InputCopy OutputCopy
Input #2
6 4
1 2
2 3
2 4
4 5
4 6
2 4 5 6
Output #2
2
4
InputCopy OutputCopy
题目信息
题号
592D
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
动态规划
图论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。