n,u,v = map(int,input().split())
edge = [[] for _ in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)
q = []
step = [0 for _ in range(n+1)]
q.append([v,0])
visied = set()
visied.add(v)
while len(q)>0:
    a,v = q.pop()
    visied.add(a)
    for node in edge[a]:
        if node not in visied:
            step[node] = v+1
            q.append([node,v+1])
q =[]
q.append([u,0])
mx= 0
while len(q)>0:
    a, v = q.pop()
    p=0
    for node in edge[a]:
        cur = v+1
        if cur<step[node]:
            q.append([node,cur])
            p=1
        else:
            mx = max(mx,step[node])
    if p ==0:
        # print(node,step[node])
        mx = max(mx,step[node])
# print(step)
print(mx)
