CF592D.Super M

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn cities, connected by n1n-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 mm 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.

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.

输入格式

The first line of the input contains two integers nn and mm ( 1<=m<=n<=1234561<=m<=n<=123456 ) - the number of cities in Byteforces, and the number of cities being attacked respectively.

Then follow n1n-1 lines, describing the road system. Each line contains two city numbers uiu_{i} and viv_{i} ( 1<=ui,vi<=n1<=u_{i},v_{i}<=n ) - the ends of the road ii .

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

输出格式

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.

输入输出样例

  • 输入#1

    7 2
    1 2
    1 3
    1 4
    3 5
    3 6
    3 7
    2 7
    

    输出#1

    2
    3
    
  • 输入#2

    6 4
    1 2
    2 3
    2 4
    4 5
    4 6
    2 4 5 6
    

    输出#2

    2
    4
    

说明/提示

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

and .

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

首页