import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
def prime_decomposition(n): #素因数分解
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(int(n))
  return table

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

import heapq
import sys

input = sys.stdin.readline

def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
#########################
n,w,p = map(int,input().split())

edge = [[] for i in range(n)]
dg = 10**7
#隣接リスト edge[i]:[コスト,行先]
for i in range(n-1):
    x,y = map(int,input().split())
    z = 1
    x -= 1
    y -= 1
    edge[x].append(dg + y)
    edge[y].append(dg + x)

import heapq



#edge[i]:[ cost1*dg + j1,...] 
"""
for _ in [0]*m:
    u,v,w = map(int,input().split())
    edge[u-1].append(w*dg+v-1)
    #edge[v-1].append(w*dg+u-1)
"""

#dijkstra
# d : minimum distance from s
s = w-1
ss = p-1
d = [-1]*n
d[s] = 0

d2 = [-1]*n
d2[ss] = 0
edgelist = []
edgelist2 = []
for e in edge[s]:
    heapq.heappush(edgelist,e)

for e in edge[ss]:
    heapq.heappush(edgelist2,e)
    

while len(edgelist):
    minedge = heapq.heappop(edgelist)
    v,c = minedge%dg,minedge//dg
    if d[v] >= 0:
        continue
    d[v] = c
    for e in edge[v]:
        vNext = e%dg
        if d[vNext]:
            heapq.heappush(edgelist, (e//dg+d[v])*dg + vNext)

while len(edgelist2):
    minedge = heapq.heappop(edgelist2)
    v,c = minedge%dg,minedge//dg
    if d2[v] >= 0:
        continue
    d2[v] = c
    for e in edge[v]:
        vNext = e%dg
        if d2[vNext]:
            heapq.heappush(edgelist2, (e//dg+d2[v])*dg + vNext)


co = 0
for i in range(n):
    if co < d2[i] and d2[i]-d[i]>=0:
        co = d2[i]

print(co-1)



Measured memory_bytes: 99612