#!/usr/bin/env python3



import sys

import math

from bisect import bisect_right as br

from bisect import bisect_left as bl

sys.setrecursionlimit(1000000)

from heapq import heappush, heappop,heappushpop

from collections import defaultdict

from itertools import accumulate

from collections import Counter

from collections import deque

from operator import itemgetter

from itertools import permutations

mod = 10**9 + 7

inf = float('inf')

def I(): return int(sys.stdin.readline())

def LI(): return list(map(int,sys.stdin.readline().split()))





n,V,U = LI()

V -= 1

U -= 1



edges = [[] for _ in range(n)]



for _ in range(n-1):

    a,b = LI()

    edges[a-1].append(b-1)

    edges[b-1].append(a-1)



if n == 2:

    print((0))

else:

    depth_v = [None]*n

    depth_v[V] = 0

    que = deque()

    que.append(V)

    while que:

        v = que.popleft()

        for u in edges[v]:

            if depth_v[u] == None:

                depth_v[u] = depth_v[v]+1

                que.append(u)

    

    depth_u = [None]*n

    depth_u[U] = 0

    que = deque()

    que.append(U)

    while que:

        u = que.popleft()

        for v in edges[u]:

            if depth_u[v] == None:

                depth_u[v] = depth_u[u] + 1

                que.append(v)

    

    ans = 0

    for v in range(n):

        if depth_v[v] < depth_u[v]:

            ans = max(ans,depth_u[v]-1)

    print(ans)
#!/usr/bin/env python3



import sys

import math

from bisect import bisect_right as br

from bisect import bisect_left as bl

sys.setrecursionlimit(1000000)

from heapq import heappush, heappop,heappushpop

from collections import defaultdict

from itertools import accumulate

from collections import Counter

from collections import deque

from operator import itemgetter

from itertools import permutations

mod = 10**9 + 7

inf = float('inf')

def I(): return int(sys.stdin.readline())

def LI(): return list(map(int,sys.stdin.readline().split()))



"""

[考察]

　高橋君が最も遠くに逃げる場合

　:= (高橋君が先に行ける頂点)Λ(青木君から最も遠い頂点)



⇒高橋君が先に行ける頂点

　高橋君からの各頂点の距離(高橋君を根としたときの木の深さ),

　青木君からの各頂点の距離(青木君を根としたときの木の深さ)を求めて、

　高橋君からの距離と青木君からの距離を比較

⇒青木君から最も遠い頂点

　青木君からの各頂点の距離の最大値

"""

n,V,U = LI()

V -= 1

U -= 1



edges = [[] for _ in range(n)]



for _ in range(n-1):

    a,b = LI()

    edges[a-1].append(b-1)

    edges[b-1].append(a-1)



if n == 2:

    print((0))

else:

    depth_v = [None]*n

    depth_v[V] = 0

    que = deque()

    que.append(V)

    while que:

        v = que.popleft()

        for u in edges[v]:

            if depth_v[u] == None:

                depth_v[u] = depth_v[v]+1

                que.append(u)

    

    depth_u = [None]*n

    depth_u[U] = 0

    que = deque()

    que.append(U)

    while que:

        u = que.popleft()

        for v in edges[u]:

            if depth_u[v] == None:

                depth_u[v] = depth_u[u] + 1

                que.append(v)

    

    ans = 0

    for v in range(n):

        if depth_v[v] < depth_u[v]:

            ans = max(ans,depth_u[v]-1)

    print(ans)
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl

sys.setrecursionlimit(1000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations

mod = 10**9 + 7
inf = float("inf")


def I():
    return int(sys.stdin.readline())


def LI():
    return list(map(int, sys.stdin.readline().split()))


n, V, U = LI()
V -= 1
U -= 1
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = LI()
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
if n == 2:
    print((0))
else:
    depth_v = [None] * n
    depth_v[V] = 0
    que = deque()
    que.append(V)
    while que:
        v = que.popleft()
        for u in edges[v]:
            if depth_v[u] == None:
                depth_v[u] = depth_v[v] + 1
                que.append(u)
    depth_u = [None] * n
    depth_u[U] = 0
    que = deque()
    que.append(U)
    while que:
        u = que.popleft()
        for v in edges[u]:
            if depth_u[v] == None:
                depth_u[v] = depth_u[u] + 1
                que.append(v)
    ans = 0
    for v in range(n):
        if depth_v[v] < depth_u[v]:
            ans = max(ans, depth_u[v] - 1)
    print(ans)

#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl

sys.setrecursionlimit(1000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations

mod = 10**9 + 7
inf = float("inf")


def I():
    return int(sys.stdin.readline())


def LI():
    return list(map(int, sys.stdin.readline().split()))


"""
[考察]
　高橋君が最も遠くに逃げる場合
　:= (高橋君が先に行ける頂点)Λ(青木君から最も遠い頂点)
⇒高橋君が先に行ける頂点
　高橋君からの各頂点の距離(高橋君を根としたときの木の深さ),
　青木君からの各頂点の距離(青木君を根としたときの木の深さ)を求めて、
　高橋君からの距離と青木君からの距離を比較
⇒青木君から最も遠い頂点
　青木君からの各頂点の距離の最大値
"""
n, V, U = LI()
V -= 1
U -= 1
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = LI()
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
if n == 2:
    print((0))
else:
    depth_v = [None] * n
    depth_v[V] = 0
    que = deque()
    que.append(V)
    while que:
        v = que.popleft()
        for u in edges[v]:
            if depth_v[u] == None:
                depth_v[u] = depth_v[v] + 1
                que.append(u)
    depth_u = [None] * n
    depth_u[U] = 0
    que = deque()
    que.append(U)
    while que:
        u = que.popleft()
        for v in edges[u]:
            if depth_u[v] == None:
                depth_u[v] = depth_u[u] + 1
                que.append(v)
    ans = 0
    for v in range(n):
        if depth_v[v] < depth_u[v]:
            ans = max(ans, depth_u[v] - 1)
    print(ans)

+""" +[考察] +　高橋君が最も遠くに逃げる場合 +　:= (高橋君が先に行ける頂点)Λ(青木君から最も遠い頂点) +⇒高橋君が先に行ける頂点 +　高橋君からの各頂点の距離(高橋君を根としたときの木の深さ), +　青木君からの各頂点の距離(青木君を根としたときの木の深さ)を求めて、 +　高橋君からの距離と青木君からの距離を比較 +⇒青木君から最も遠い頂点 +　青木君からの各頂点の距離の最大値 +"""