def main():

    from functools import lru_cache

    import sys

    input=sys.stdin.readline

    sys.setrecursionlimit(100000000)



    n,u,v=list(map(int,input().split()))

    u-=1

    v-=1

    tree=[[] for i in range(n)]

    for i in range(n-1):

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

        a-=1

        b-=1

        tree[a].append(b)

        tree[b].append(a)

    

    depth=[0]*n

    depth[v]=0

    def dfs(i,before=-1):

        for e in tree[i]:

            if e!=before:

                depth[e]=depth[i]+1

                dfs(e,i)

    dfs(v)

    #print(depth)

    

    max_depth=[-1]*n

    max_depth[v]=0   

    @lru_cache(maxsize=None)

    def dfs2(i,before=-1):

        t=-1

        for e in tree[i]:

            if e!=before:

                t=max(t,dfs2(e,i))

        if t!=-1:

            max_depth[i]=t

            return max_depth[i]

        else:

            max_depth[i]=depth[i]

            return max_depth[i]

            

    dfs2(v)   

    #print(max_depth)

    

    lim=depth[u]

    i,key=u,u

    while i!=v:

        if 2*depth[i]>lim and max_depth[key] < max_depth[i]:

            key=i

            

        for e in tree[i]:

            if depth[e]<depth[i]:

                i=e

                break

                

    print((max_depth[key]-1)) 

if __name__=='__main__':

    main()



def main():

    import sys

    input=sys.stdin.readline

    sys.setrecursionlimit(100000000)



    n,u,v=list(map(int,input().split()))

    u-=1

    v-=1

    tree=[[] for i in range(n)]

    for i in range(n-1):

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

        a-=1

        b-=1

        tree[a].append(b)

        tree[b].append(a)

    

    depth_u=[0]*n #uからの距離

    depth_v=[0]*n #vからの距離

    

    def dfs1(i,before=-1):

        for e in tree[i]:

            if e!=before:

                depth_u[e]=depth_u[i]+1

                dfs1(e,i)

    

    def dfs2(i,before=-1):

        for e in tree[i]:

            if e!=before:

                depth_v[e]=depth_v[i]+1

                dfs2(e,i)

    

    dfs1(u)

    dfs2(v)



    ans=depth_v[u]-1

    for i in range(n):

        if len(tree[i])==1 and depth_u[i]<depth_v[i]:

                ans=max(ans,depth_v[i]-1)

    print(ans)



if __name__=='__main__':

    main()
def main():
    from functools import lru_cache
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(100000000)
    n, u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    tree = [[] for i in range(n)]
    for i in range(n - 1):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        tree[a].append(b)
        tree[b].append(a)
    depth = [0] * n
    depth[v] = 0

    def dfs(i, before=-1):
        for e in tree[i]:
            if e != before:
                depth[e] = depth[i] + 1
                dfs(e, i)

    dfs(v)
    # print(depth)
    max_depth = [-1] * n
    max_depth[v] = 0

    @lru_cache(maxsize=None)
    def dfs2(i, before=-1):
        t = -1
        for e in tree[i]:
            if e != before:
                t = max(t, dfs2(e, i))
        if t != -1:
            max_depth[i] = t
            return max_depth[i]
        else:
            max_depth[i] = depth[i]
            return max_depth[i]

    dfs2(v)
    # print(max_depth)
    lim = depth[u]
    i, key = u, u
    while i != v:
        if 2 * depth[i] > lim and max_depth[key] < max_depth[i]:
            key = i
        for e in tree[i]:
            if depth[e] < depth[i]:
                i = e
                break
    print((max_depth[key] - 1))


if __name__ == "__main__":
    main()

def main():
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(100000000)
    n, u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    tree = [[] for i in range(n)]
    for i in range(n - 1):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        tree[a].append(b)
        tree[b].append(a)
    depth_u = [0] * n  # uからの距離
    depth_v = [0] * n  # vからの距離

    def dfs1(i, before=-1):
        for e in tree[i]:
            if e != before:
                depth_u[e] = depth_u[i] + 1
                dfs1(e, i)

    def dfs2(i, before=-1):
        for e in tree[i]:
            if e != before:
                depth_v[e] = depth_v[i] + 1
                dfs2(e, i)

    dfs1(u)
    dfs2(v)
    ans = depth_v[u] - 1
    for i in range(n):
        if len(tree[i]) == 1 and depth_u[i] < depth_v[i]:
            ans = max(ans, depth_v[i] - 1)
    print(ans)


if __name__ == "__main__":
    main()

-    from functools import lru_cache -    depth = [0] * n -    depth[v] = 0 +    depth_u = [0] * n  # uからの距離 +    depth_v = [0] * n  # vからの距離 -    def dfs(i, before=-1): +    def dfs1(i, before=-1): -                depth[e] = depth[i] + 1 -                dfs(e, i) +                depth_u[e] = depth_u[i] + 1 +                dfs1(e, i) -    dfs(v) -    # print(depth) -    max_depth = [-1] * n -    max_depth[v] = 0 - -    @lru_cache(maxsize=None) -        t = -1 -                t = max(t, dfs2(e, i)) -        if t != -1: -            max_depth[i] = t -            return max_depth[i] -        else: -            max_depth[i] = depth[i] -            return max_depth[i] +                depth_v[e] = depth_v[i] + 1 +                dfs2(e, i) +    dfs1(u) -    # print(max_depth) -    lim = depth[u] -    i, key = u, u -    while i != v: -        if 2 * depth[i] > lim and max_depth[key] < max_depth[i]: -            key = i -        for e in tree[i]: -            if depth[e] < depth[i]: -                i = e -                break -    print((max_depth[key] - 1)) +    ans = depth_v[u] - 1 +    for i in range(n): +        if len(tree[i]) == 1 and depth_u[i] < depth_v[i]: +            ans = max(ans, depth_v[i] - 1) +    print(ans)