import copy

n, u, v = map(int, input().split())
graph = {i + 1:[] for i in range(n)}
for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
graph2 = copy.deepcopy(graph)
taka = [u]
aoki = [v]
list_t = [[u]]
list_a = [[v]]
num = 0
while list_t or list_a:
    temp_a = []
    temp_t = []
    if list_a:
        check_a = list_a.pop(0)
        for i in check_a:
            for j in graph[i]:
                if j not in taka:
                    aoki.append(j)
                    temp_a.append(j)
                    graph[j].remove(i)
        if temp_a:
            list_a.append(temp_a)
    if list_t:
        check_t = list_t.pop(0)
        for i in check_t:
            for j in graph[i]:
                if j not in aoki:
                    taka.append(j)
                    temp_t.append(j)
                    graph[j].remove(i)
        if list_t:
            list_t.append(temp_t)
list_d = []
for i in check_a:
    dis = 0
    check_list = [[i]]
    while check_list:
        check = check_list.pop(0)
        temp = []
        for j in check:
            for k in graph2[j]:
                temp.append(k)
                graph2[k].remove(j)
        if temp:
            check_list.append(temp)
            dis += 1
    list_d.append(dis)
print(max(list_d) - 1)