# coding: utf-8
# Your code here!
import copy
N,u,v=map(int,input().split())
l=[set()for i in range(N)]
info=[[-1,-1,-1,-1]for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    l[a-1].add(b-1)
    l[b-1].add(a-1)
terminal=set()

s={u-1}
info[u-1][0]=0
info[u-1][1]=0
k=1
while len(s)>0:
    new_s=set()
    for t in s:
        for t2 in l[t]:
            if info[t2][0]==-1:
                info[t2][0]=t
                info[t2][1]=k
                new_s.add(t2)
    s=new_s
    k+=1

s={v-1}
info[v-1][2]=0
info[v-1][3]=0
k=1
while len(s)>0:
    new_s=set()
    for t in s:
        for t2 in l[t]:
            if  info[t2][2]==-1:
                info[t2][2]=t
                info[t2][3]=k
                new_s.add(t2)
    s=new_s
    k+=1
ans=-1
d=0
print(l)
print(info)
for i in range(N):
    if not len(l[i])==1:continue
    if info[i][1]<info[i][3]:
        if d<info[i][3]:
            d=info[i][3]
print(d-1)