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.


-----Examples-----
Input
7 2
1 2
1 3
1 4
3 5
3 6
3 7
2 7

Output
2
3

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

Output
2
4



-----Note-----

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

$2 \rightarrow 1 \rightarrow 3 \rightarrow 7$ and $7 \rightarrow 3 \rightarrow 1 \rightarrow 2$.

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

Difficulty: interview

Starter code:

Solutions:
from collections import deque
n,m = [int(x) for x in input().split()]
adj = [[] for x in range(n+1)]
for _ in range(1,n):
	a,b = [int(x) for x in input().split()]
	adj[a].append(b)
	adj[b].append(a)
chaos = [int(x) for x in input().split()]
s = chaos[0]
chaos = set(chaos)
cc = [0]*(n+1)
st = deque()
st.append((s,-1))
while len(st):
	u,e = st.pop()
	if u<0:
		if e>=0:
			cc[e] += cc[-u]
		continue
	if u in chaos:
		cc[u] +=1
	st.append((-u,e))
	
	for v in adj[u]:
		if v!=e:
			st.append((v,u))
	
#dfs(s,-1)
adj = [list([v for v in u if cc[v]>0]) for u in adj]
a = (s,0)
st = deque()
st.append((a[0],-1,0))
while len(st):
	u,e,h = st.pop()
	if h>a[1]:
		a = (u,h)
	elif h==a[1] and u<a[0]:
		a = (u,h)
	for v in adj[u]:
		if v!=e:
			st.append((v,u,h+1))
b = a
a = (a[0],0)
st = deque()
st.append((a[0],-1,0))
while len(st):
	u,e,h = st.pop()
	if h>a[1]:
		a = (u,h)
	elif h==a[1] and u<a[0]:
		a = (u,h)
	for v in adj[u]:
		if v!=e:
			st.append((v,u,h+1))
print(min(a[0],b[0]))
print(2*(n-cc.count(0))-a[1])


from collections import deque
from sys import stdin

#parser
def parser():
    return map(int, stdin.readline().split())

def DFS_Discriminiting():
    #visitados
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    intrudoction_order=[]
    stack.append(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                pi[u]=v
                visited[u]=True
                if attacked_city[u]:
                    count_attacked_cities_subtree[u]+=1
                stack.append(u)
                intrudoction_order.append(u)    
    for v in intrudoction_order[::-1]:
        count_attacked_cities_subtree[pi[v]]+=count_attacked_cities_subtree[v]
        if count_attacked_cities_subtree[v]==0:
            important_cities[v]=False

def DFS_Heigths():
    #visitados
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    intrudoction_order=[]
    stack.append(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                pi[u]=v
                visited[u]=True
                stack.append(u)
                intrudoction_order.append(u)
    for v in intrudoction_order[::-1]:
        if heights1[pi[v]] < heights1[v]+1:
            heights2[pi[v]]=heights1[pi[v]]
            heights1[pi[v]]=heights1[v]+1
        elif heights2[pi[v]]<heights1[v]+1:
            heights2[pi[v]]=heights1[v]+1

def Distance_Root(s):
    for v in adjacents_list[s]:
        if heights1[v]+1>distances1[s]:
            distances2[s]=distances1[s]
            distances1[s]=heights1[v]+1
        elif heights1[v]+1>distances2[s]:
            distances2[s]=heights1[v]+1

def DFS_Distances():
    #visitados
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    stack.append(numbers_of_attacked_cities[0])
    Distance_Root(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                pi[u]=v
                visited[u]=True
                determinate=False
                stack.append(u)
                if heights1[u]+1==distances1[v]:
                    if heights1[u]+1>distances2[v]:
                        determinate=True
                        distances1[u]=max(heights1[u],distances2[v]+1)
                        if distances1[u]==heights1[u]:
                            distances2[u]=max(distances2[v]+1,heights2[u])
                        else:
                            distances2[u]=heights1[u]
                if not determinate:
                    distances1[u]=distances1[v]+1
                    distances2[u]=heights1[u]

def BFS(s):
    distance=[-1 for x in range(n)]
    distance[s]=0
    q=deque()
    q.append(s)
    while len(q)>0:
        v=q.popleft()
        for u in adjacents_list[v]:
            if distance[u] == -1:
                distance[u]=distance[v]+1
                q.append(u)
    return distance


n,m=parser()
#Creando los arrays necesarios para la ejecucion de DFS
#padres
pi=[0 for x in range(n)]
#ciudades atacadas en el subarbol
count_attacked_cities_subtree=[0 for x in range(n)]
#ciudad atacada o no atacada
attacked_city=[False for x in range(n)]
#ciudades_que_son atacadas o sirven para llegar a las mismas
important_cities=[True for x in range(n)]

adjacents_list=[[] for x in range(n)]
for i in range(n-1):
    v1,v2=parser()
    adjacents_list[v1-1].append(v2-1)
    adjacents_list[v2-1].append(v1-1)

#numero de ciudades atacadas
numbers_of_attacked_cities=[x-1 for x in parser()]

if m==1:
    print(numbers_of_attacked_cities[0]+1)
    print(0)
    return

#marcando las ciudades atacadas
for i in numbers_of_attacked_cities:
    attacked_city[i]=True

DFS_Discriminiting()

adjacents_list=[[] for x in range(n)]

count_edges=0
for v in range(n):
    if v==numbers_of_attacked_cities[0]:
        continue
    elif important_cities[v] and important_cities[pi[v]]:
        adjacents_list[v].append(pi[v])
        adjacents_list[pi[v]].append(v)
        count_edges+=1

#padres
pi=[0 for x in range(n)]

#alturas
heights1=[0 for x in range(n)]
heights2=[0 for x in range(n)]

DFS_Heigths()

#distances
distances1=[0 for x in range(n)]
distances2=[0 for x in range(n)]

DFS_Distances()

lower=distances1[numbers_of_attacked_cities[0]]
for i in range(n):
    if important_cities[i] and lower>distances1[i]:
        lower=distances1[i]

centers=[]
for i in range(n):
    if distances1[i]==lower:
        centers.append(i)


posibles_begin_cities=[]

for i in centers:
    distances_center=BFS(i)
    max_distance=0
    for j in range(n):
        if distances_center[j]>max_distance:
            max_distance=distances_center[j]
    for j in range(n):
        if distances_center[j]==max_distance:
            posibles_begin_cities.append(j)


print(min(posibles_begin_cities)+1)

print(2*count_edges-(distances1[centers[0]]+distances2[centers[0]]))

from collections import deque
from sys import stdin

#parser
def parser():
    return map(int, stdin.readline().split())

def DFS_Discriminiting():
    #visitados
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    intrudoction_order=[]
    stack.append(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                pi[u]=v
                visited[u]=True
                if attacked_city[u]:
                    count_attacked_cities_subtree[u]+=1
                stack.append(u)
                intrudoction_order.append(u)    
    for v in intrudoction_order[::-1]:
        count_attacked_cities_subtree[pi[v]]+=count_attacked_cities_subtree[v]
        if count_attacked_cities_subtree[v]==0:
            important_cities[v]=False

def DFS_Heigths():
    #visitados
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    intrudoction_order=[]
    stack.append(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                pi[u]=v
                visited[u]=True
                stack.append(u)
                intrudoction_order.append(u)
    for v in intrudoction_order[::-1]:
        if heights1[pi[v]] < heights1[v]+1:
            heights2[pi[v]]=heights1[pi[v]]
            heights1[pi[v]]=heights1[v]+1
        elif heights2[pi[v]]<heights1[v]+1:
            heights2[pi[v]]=heights1[v]+1

def Distance_Root(s):
    for v in adjacents_list[s]:
        if heights1[v]+1>distances1[s]:
            distances2[s]=distances1[s]
            distances1[s]=heights1[v]+1
        elif heights1[v]+1>distances2[s]:
            distances2[s]=heights1[v]+1

def DFS_Distances():
    #visitados
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    stack.append(numbers_of_attacked_cities[0])
    Distance_Root(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                pi[u]=v
                visited[u]=True
                determinate=False
                stack.append(u)
                if heights1[u]+1==distances1[v]:
                    if heights1[u]+1>distances2[v]:
                        determinate=True
                        distances1[u]=max(heights1[u],distances2[v]+1)
                        if distances1[u]==heights1[u]:
                            distances2[u]=max(distances2[v]+1,heights2[u])
                        else:
                            distances2[u]=heights1[u]
                if not determinate:
                    distances1[u]=distances1[v]+1
                    distances2[u]=heights1[u]

def BFS(s):
    distance=[-1 for x in range(n)]
    distance[s]=0
    q=deque()
    q.append(s)
    while len(q)>0:
        v=q.popleft()
        for u in adjacents_list[v]:
            if distance[u] == -1:
                distance[u]=distance[v]+1
                q.append(u)
    return distance


n,m=parser()
#Creando los arrays necesarios para la ejecucion de DFS
#padres
pi=[0 for x in range(n)]
#ciudades atacadas en el subarbol
count_attacked_cities_subtree=[0 for x in range(n)]
#ciudad atacada o no atacada
attacked_city=[False for x in range(n)]
#ciudades_que_son atacadas o sirven para llegar a las mismas
important_cities=[True for x in range(n)]

adjacents_list=[[] for x in range(n)]
for i in range(n-1):
    v1,v2=parser()
    adjacents_list[v1-1].append(v2-1)
    adjacents_list[v2-1].append(v1-1)

#numero de ciudades atacadas
numbers_of_attacked_cities=[x-1 for x in parser()]

if m==1:
    print(numbers_of_attacked_cities[0]+1)
    print(0)
    return

#marcando las ciudades atacadas
for i in numbers_of_attacked_cities:
    attacked_city[i]=True

DFS_Discriminiting()

adjacents_list=[[] for x in range(n)]

count_edges=0
for v in range(n):
    if v==numbers_of_attacked_cities[0]:
        continue
    elif important_cities[v] and important_cities[pi[v]]:
        adjacents_list[v].append(pi[v])
        adjacents_list[pi[v]].append(v)
        count_edges+=1

#padres
pi=[0 for x in range(n)]

#alturas
heights1=[0 for x in range(n)]
heights2=[0 for x in range(n)]

DFS_Heigths()

#distances
distances1=[0 for x in range(n)]
distances2=[0 for x in range(n)]

DFS_Distances()

lower=distances1[numbers_of_attacked_cities[0]]
for i in range(n):
    if important_cities[i] and lower>distances1[i]:
        lower=distances1[i]

centers=[]
for i in range(n):
    if distances1[i]==lower:
        centers.append(i)


posibles_begin_cities=[]

for i in centers:
    distances_center=BFS(i)
    max_distance=0
    for j in range(n):
        if distances_center[j]>max_distance:
            max_distance=distances_center[j]
    for j in range(n):
        if distances_center[j]==max_distance:
            posibles_begin_cities.append(j)


print(min(posibles_begin_cities)+1)

print(2*count_edges-(distances1[centers[0]]+distances2[centers[0]]))

from collections import deque

#parser
def parser():
    return [int(x) for x in input().split()]

def DFS_Discriminiting():
    #visitados
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    intrudoction_order=[]
    stack.append(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                pi[u]=v
                visited[u]=True
                if attacked_city[u]:
                    count_attacked_cities_subtree[u]+=1
                stack.append(u)
                intrudoction_order.append(u)    
    for v in intrudoction_order[::-1]:
        count_attacked_cities_subtree[pi[v]]+=count_attacked_cities_subtree[v]
        if count_attacked_cities_subtree[v]==0:
            important_cities[v]=False

def DFS_Heigths():
    #visitados
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    intrudoction_order=[]
    stack.append(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                pi[u]=v
                visited[u]=True
                stack.append(u)
                intrudoction_order.append(u)
    for v in intrudoction_order[::-1]:
        if heights1[pi[v]] < heights1[v]+1:
            heights2[pi[v]]=heights1[pi[v]]
            heights1[pi[v]]=heights1[v]+1
        elif heights2[pi[v]]<heights1[v]+1:
            heights2[pi[v]]=heights1[v]+1

def Distance_Root(s):
    for v in adjacents_list[s]:
        if heights1[v]+1>distances1[s]:
            distances2[s]=distances1[s]
            distances1[s]=heights1[v]+1
        elif heights1[v]+1>distances2[s]:
            distances2[s]=heights1[v]+1

def DFS_Distances():
    #visitados
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    stack.append(numbers_of_attacked_cities[0])
    Distance_Root(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                pi[u]=v
                visited[u]=True
                determinate=False
                stack.append(u)
                if heights1[u]+1==distances1[v]:
                    if heights1[u]+1>distances2[v]:
                        determinate=True
                        distances1[u]=max(heights1[u],distances2[v]+1)
                        if distances1[u]==heights1[u]:
                            distances2[u]=max(distances2[v]+1,heights2[u])
                        else:
                            distances2[u]=heights1[u]
                if not determinate:
                    distances1[u]=distances1[v]+1
                    distances2[u]=heights1[u]

def BFS(s):
    distance=[-1 for x in range(n)]
    distance[s]=0
    q=deque()
    q.append(s)
    while len(q)>0:
        v=q.popleft()
        for u in adjacents_list[v]:
            if distance[u] == -1:
                distance[u]=distance[v]+1
                q.append(u)
    return distance


n,m=parser()
#Creando los arrays necesarios para la ejecucion de DFS
#padres
pi=[0 for x in range(n)]
#ciudades atacadas en el subarbol
count_attacked_cities_subtree=[0 for x in range(n)]
#ciudad atacada o no atacada
attacked_city=[False for x in range(n)]
#ciudades_que_son atacadas o sirven para llegar a las mismas
important_cities=[True for x in range(n)]

adjacents_list=[[] for x in range(n)]
for i in range(n-1):
    edge=parser()
    adjacents_list[edge[0]-1].append(edge[1]-1)
    adjacents_list[edge[1]-1].append(edge[0]-1)

#numero de ciudades atacadas
numbers_of_attacked_cities=[]
for i in parser():
    numbers_of_attacked_cities.append(i-1)

if m==1:
    print(numbers_of_attacked_cities[0]+1)
    print(0)
    return

#marcando las ciudades atacadas
for i in numbers_of_attacked_cities:
    attacked_city[i]=True

DFS_Discriminiting()

adjacents_list=[[] for x in range(n)]

count_edges=0
for v in range(n):
    if v==numbers_of_attacked_cities[0]:
        continue
    elif important_cities[v] and important_cities[pi[v]]:
        adjacents_list[v].append(pi[v])
        adjacents_list[pi[v]].append(v)
        count_edges+=1

#padres
pi=[0 for x in range(n)]

#alturas
heights1=[0 for x in range(n)]
heights2=[0 for x in range(n)]

DFS_Heigths()

#distances
distances1=[0 for x in range(n)]
distances2=[0 for x in range(n)]

DFS_Distances()

lower=distances1[numbers_of_attacked_cities[0]]
for i in range(n):
    if important_cities[i] and lower>distances1[i]:
        lower=distances1[i]

centers=[]
for i in range(n):
    if distances1[i]==lower:
        centers.append(i)


posibles_begin_cities=[]

for i in centers:
    distances_center=BFS(i)
    max_distance=0
    for j in range(n):
        if distances_center[j]>max_distance:
            max_distance=distances_center[j]
    for j in range(n):
        if distances_center[j]==max_distance:
            posibles_begin_cities.append(j)


print(min(posibles_begin_cities)+1)

print(2*count_edges-(distances1[centers[0]]+distances2[centers[0]]))

from heapq import *
INF = float('inf')
n, m = list(map(int, input().split()))
adj = [[] for _ in range(n+1)]
wg= ng = [0 for _ in range(n+1)]

for _ in range(n-1):
    a, b = list(map(int, input().split()))
    adj[a].append(b)
    adj[b].append(a)

aaa = set(map(int, input().split()))
if len(aaa) == 1:print((min(aaa)));print((0));return
rm = []
for i in range(n+1):
    ng[i] = len(adj[i])
    if i not in aaa and ng[i] == 1: rm.append(i)

for a in aaa: ng[a] = 0

def remove_node(index):
    while adj[index]:
        nx = adj[index].pop()
        adj[nx].remove(index)
        ng[nx] -= 1
        if ng[nx] == 1: rm.append(nx)

    ng[index] = 0

while rm: remove_node(rm.pop())

state = [0 for _ in range(n+1)]
que = [(min(aaa), None)]
res = 0
for _ in range(2):
    deep = [0 for _ in range(n + 1)]
    while que:
        res += 1
        root, proot = que.pop()
        for nx in adj[root]:
            if proot == nx:
                continue
            if _: state[nx] = root
            deep[nx] = deep[root] + 1
            que.append((nx, root))
    if _: break

    start = max(1,deep.index(max(deep)))
    que = [(start, None)]

end = max(1, deep.index(max(deep)))
i = end
path = 1
while i != start:
    path += 1
    i = state[i]

print(min(start,end))
print(res -1 -path)


from collections import deque
from sys import stdin

#parsea una línea
def parser():
    return map(int, stdin.readline().split())

#Método usado para obtener los vértices por los que debe pasar Super M
def DFS_Discriminiting():
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    introduction_order=[]
    stack.append(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                pi[u]=v
                visited[u]=True
                if attacked_city[u]:
                    count_attacked_cities_subtree[u]+=1
                stack.append(u)
                introduction_order.append(u)    
    for v in introduction_order[::-1]:
        count_attacked_cities_subtree[pi[v]]+=count_attacked_cities_subtree[v]
        if count_attacked_cities_subtree[v]==0:
            important_cities[v]=False

#Método usado para calcular las alturas
def DFS_Heigths():
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    introduction_order=[]
    stack.append(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                visited[u]=True
                stack.append(u)
                introduction_order.append(u)
    for v in introduction_order[::-1]:
        if heights1[pi[v]] < heights1[v]+1:
            heights2[pi[v]]=heights1[pi[v]]
            heights1[pi[v]]=heights1[v]+1
        elif heights2[pi[v]]<heights1[v]+1:
            heights2[pi[v]]=heights1[v]+1

#Método usado para calcular la primera y segunda distancia de la raíz 
def Distance_Root(s):
    for v in adjacents_list[s]:
        if heights1[v]+1>distances1[s]:
            distances2[s]=distances1[s]
            distances1[s]=heights1[v]+1
        elif heights1[v]+1>distances2[s]:
            distances2[s]=heights1[v]+1

#Método usado para calcular la primera distancia y segunda distancia de cada vértice
def DFS_Distances():
    #visitados
    visited=[False for x in range(n)]
    visited[numbers_of_attacked_cities[0]]=True
    stack=[]
    stack.append(numbers_of_attacked_cities[0])
    Distance_Root(numbers_of_attacked_cities[0])
    while len(stack)>0:
        v=stack.pop()
        for u in adjacents_list[v]:
            if not visited[u]:
                visited[u]=True
                stack.append(u)
                determinate=False
                if heights1[u]+1==distances1[v]:
                    if heights1[u]+1>distances2[v]:
                        determinate=True
                        distances1[u]=max(heights1[u],distances2[v]+1)
                        if distances1[u]==heights1[u]:
                            distances2[u]=max(distances2[v]+1,heights2[u])
                        else:
                            distances2[u]=heights1[u]
                if not determinate:
                    distances1[u]=distances1[v]+1
                    distances2[u]=heights1[u]

#Método usado para calcular las distancias de un vétice al resto de los vértices
def BFS(s):
    distance=[-1 for x in range(n)]
    distance[s]=0
    q=deque()
    q.append(s)
    while len(q)>0:
        v=q.popleft()
        for u in adjacents_list[v]:
            if distance[u] == -1:
                distance[u]=distance[v]+1
                q.append(u)
    return distance

#Recibiendo los valores de n y m
n,m=parser()
#padres
pi=[0 for x in range(n)]
#ciudades atacadas en el subarbol
count_attacked_cities_subtree=[0 for x in range(n)]
#ciudad atacada o no atacada
attacked_city=[False for x in range(n)]
#ciudades_que_son atacadas o sirven para llegar a las mismas
important_cities=[True for x in range(n)]

#Armando el árbol que representa a Byteforces
adjacents_list=[[] for x in range(n)]
for i in range(n-1):
    v1,v2=parser()
    adjacents_list[v1-1].append(v2-1)
    adjacents_list[v2-1].append(v1-1)

#número de ciudades atacadas
numbers_of_attacked_cities=[x-1 for x in parser()]
if m==1:
    print(numbers_of_attacked_cities[0]+1)
    print(0)
    return

#marcando las ciudades atacadas
for i in numbers_of_attacked_cities:
    attacked_city[i]=True

#Obteniendo las ciudades que recorre Super M
DFS_Discriminiting()

#Creando el nuevo árbol que representa el recorrido de Super M
adjacents_list=[[] for x in range(n)]

#Armando el nuevo árbol y contando sus aristas
count_edges=0
for v in range(n):
    if v==numbers_of_attacked_cities[0]:
        continue
    elif important_cities[v] and important_cities[pi[v]]:
        adjacents_list[v].append(pi[v])
        adjacents_list[pi[v]].append(v)
        count_edges+=1

#alturas
heights1=[0 for x in range(n)]
heights2=[0 for x in range(n)]

#Calculando las alturas
DFS_Heigths()

#distancias
distances1=[0 for x in range(n)]
distances2=[0 for x in range(n)]

#Calculando las distancias
DFS_Distances()

#Hallando la mayor distancia de las primeras distancias
min_distance=distances1[numbers_of_attacked_cities[0]]
for i in range(n):
    if important_cities[i] and min_distance>distances1[i]:
        min_distance=distances1[i]

#Hallando el centro
center=[]
for i in range(n):
    if distances1[i]==min_distance:
        center.append(i)

posibles_begin_cities=[]

#Hallando la ciudad por la cual comenzar
for i in center:
    distances_center=BFS(i)
    max_distance=0
    for j in range(n):
        if distances_center[j]>max_distance:
            max_distance=distances_center[j]
    for j in range(n):
        if distances_center[j]==max_distance:
            posibles_begin_cities.append(j)

#Imprimiendo la respuesta
print(min(posibles_begin_cities)+1)
print(2*count_edges-(distances1[center[0]]+distances2[center[0]]))