import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

#a = list(map(int, input().split()))

n,a,b = list(map(int, input().split()))
es = [[] for i in range(n+1)]

for i in range(n-1):
    p,q = list(map(int, input().split()))
    es[p].append(q)
    es[q].append(p)

dista = [9999999 for i in range(n+1)]
distb = [9999999 for i in range(n+1)]



dista[a]=0
distb[b]=0

queue = [[a,0]]
snum = 0
while(True):
    if(snum==len(queue)):
        break
    nowel = queue[snum]
    nowv = nowel[0]
    #print(nowv)
    nowdist = nowel[1]
    #print(nowdist)
    elist = es[nowv]
    for j in range(len(elist)):
        if(dista[elist[j]]>9999990):
            queue.append([elist[j],nowdist+1])
            dista[elist[j]] = nowdist+1
    snum+=1
#print(dista)


queue = [[b,0]]
snum = 0
while(True):
    if(snum==len(queue)):
        break
    nowel = queue[snum]
    nowv = nowel[0]
    #print(nowv)
    nowdist = nowel[1]
    #print(nowdist)
    elist = es[nowv]
    for j in range(len(elist)):
        if(distb[elist[j]]>9999990):
            queue.append([elist[j],nowdist+1])
            distb[elist[j]] = nowdist+1
    snum+=1
#print(distb)

acan = [0 for i in range(n+1)]

for ii in range(n):
    i = ii+1
    if(dista[i] < distb[i]):
        acan[i]=1

maxa = 0

for ii in range(n):
    i = ii+1
    if(maxa < dista[i] and acan[i]==1):
        maxa = dista[i]

print(maxa)






