n,t,a=map(int,input().split())
t-=1
a-=1
g=[[] for _ in range(n)]
uv=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
    u,v=uv[i]
    u-=1
    v-=1
    g[u].append(v)
    g[v].append(u)


from collections import deque
q=deque()
q.append(t)
g1=[0]*n
while q:
    now=q.popleft()
    l=g[now]
    for k in l:
        if g1[k]:
            continue
        g1[k]=g1[now]+1
        for s in l:
            q.append(s)
g1[t]=0

q.append(a)
g2=[0]*n
while q:
    now=q.popleft()
    l=g[now]
    for k in l:
        if g2[k]:
            continue
        g2[k]=g2[now]+1
        for s in l:
            q.append(s)
g2[a]=0

x=0
for i in range(n):
    if g1[i]<g2[i]:
        x=max(x,i)
print(g2[x]-1)
