import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

input=lambda:sys.stdin.readline().rstrip()

def resolve():

    n,x,y=list(map(int,input().split()))

    x-=1; y-=1



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

    for _ in range(n-1):

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

        u-=1; v-=1

        E[u].append(v)

        E[v].append(u)



    # x から y への path を作る(depthも)

    Q=[(x,-1)]

    prev=[None]*n

    prev[x]=-1

    depth=[None]*n

    depth[x]=0

    while(Q):

        v,p=Q.pop()

        for nv in E[v]:

            if(nv==p): continue

            prev[nv]=v

            depth[nv]=depth[v]+1

            Q.append((nv,v))



    z=y

    path=[]

    while(z!=-1):

        path.append(z)

        z=prev[z]



    # y からの depth

    Q=[(y,-1)]

    depth2=[None]*n

    depth2[y]=0

    while(Q):

        v,p=Q.pop()

        for nv in E[v]:

            if(nv==p): continue

            depth2[nv]=depth2[v]+1

            Q.append((nv,v))



    k=len(path)

    s,t=path[k//2-1],path[k//2]



    Q=[(x,-1)]

    can=[0]*n

    can[x]=1

    while(Q):

        v,p=Q.pop()

        for nv in E[v]:

            if(nv==p): continue

            if((v,nv)==(s,t) or (v,nv)==(t,s)): continue

            can[nv]=1

            Q.append((nv,v))



    d1,z=max((depth2[v],v) for v in range(n) if(can[v]))

    d2=depth[z]

    # print(d1,d2)

    # if((d1+d2)&1):

    #     d1-=1



    print((d1-1))

resolve()
import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

input=lambda:sys.stdin.readline().rstrip()

def resolve():

    n,x,y=list(map(int,input().split()))

    x-=1; y-=1

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

    for _ in range(n-1):

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

        u-=1; v-=1

        E[u].append(v)

        E[v].append(u)



    # x,y それぞれの depth を計算する

    dx=[None]*n

    dx[x]=0

    Q=[(x,-1)]

    while(Q):

        v,p=Q.pop()

        for nv in E[v]:

            if(nv==p): continue

            dx[nv]=dx[v]+1

            Q.append((nv,v))



    dy=[None]*n

    dy[y]=0

    Q=[(y,-1)]

    while(Q):

        v,p=Q.pop()

        for nv in E[v]:

            if(nv==p): continue

            dy[nv]=dy[v]+1

            Q.append((nv,v))



    # x の方が y より近い点 v に対して、その1つ手前で捕まる

    ans=0

    for v in range(n):

        if(dx[v]<dy[v]):

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



    print(ans)

resolve()
import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()


def resolve():
    n, x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    E = [[] for _ in range(n)]
    for _ in range(n - 1):
        u, v = list(map(int, input().split()))
        u -= 1
        v -= 1
        E[u].append(v)
        E[v].append(u)
    # x から y への path を作る(depthも)
    Q = [(x, -1)]
    prev = [None] * n
    prev[x] = -1
    depth = [None] * n
    depth[x] = 0
    while Q:
        v, p = Q.pop()
        for nv in E[v]:
            if nv == p:
                continue
            prev[nv] = v
            depth[nv] = depth[v] + 1
            Q.append((nv, v))
    z = y
    path = []
    while z != -1:
        path.append(z)
        z = prev[z]
    # y からの depth
    Q = [(y, -1)]
    depth2 = [None] * n
    depth2[y] = 0
    while Q:
        v, p = Q.pop()
        for nv in E[v]:
            if nv == p:
                continue
            depth2[nv] = depth2[v] + 1
            Q.append((nv, v))
    k = len(path)
    s, t = path[k // 2 - 1], path[k // 2]
    Q = [(x, -1)]
    can = [0] * n
    can[x] = 1
    while Q:
        v, p = Q.pop()
        for nv in E[v]:
            if nv == p:
                continue
            if (v, nv) == (s, t) or (v, nv) == (t, s):
                continue
            can[nv] = 1
            Q.append((nv, v))
    d1, z = max((depth2[v], v) for v in range(n) if (can[v]))
    d2 = depth[z]
    # print(d1,d2)
    # if((d1+d2)&1):
    #     d1-=1
    print((d1 - 1))


resolve()

import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()


def resolve():
    n, x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    E = [[] for _ in range(n)]
    for _ in range(n - 1):
        u, v = list(map(int, input().split()))
        u -= 1
        v -= 1
        E[u].append(v)
        E[v].append(u)
    # x,y それぞれの depth を計算する
    dx = [None] * n
    dx[x] = 0
    Q = [(x, -1)]
    while Q:
        v, p = Q.pop()
        for nv in E[v]:
            if nv == p:
                continue
            dx[nv] = dx[v] + 1
            Q.append((nv, v))
    dy = [None] * n
    dy[y] = 0
    Q = [(y, -1)]
    while Q:
        v, p = Q.pop()
        for nv in E[v]:
            if nv == p:
                continue
            dy[nv] = dy[v] + 1
            Q.append((nv, v))
    # x の方が y より近い点 v に対して、その1つ手前で捕まる
    ans = 0
    for v in range(n):
        if dx[v] < dy[v]:
            ans = max(ans, dy[v] - 1)
    print(ans)


resolve()

-    # x から y への path を作る(depthも) +    # x,y それぞれの depth を計算する +    dx = [None] * n +    dx[x] = 0 -    prev = [None] * n -    prev[x] = -1 -    depth = [None] * n -    depth[x] = 0 -            prev[nv] = v -            depth[nv] = depth[v] + 1 +            dx[nv] = dx[v] + 1 -    z = y -    path = [] -    while z != -1: -        path.append(z) -        z = prev[z] -    # y からの depth +    dy = [None] * n +    dy[y] = 0 -    depth2 = [None] * n -    depth2[y] = 0 -            depth2[nv] = depth2[v] + 1 +            dy[nv] = dy[v] + 1 -    k = len(path) -    s, t = path[k // 2 - 1], path[k // 2] -    Q = [(x, -1)] -    can = [0] * n -    can[x] = 1 -    while Q: -        v, p = Q.pop() -        for nv in E[v]: -            if nv == p: -                continue -            if (v, nv) == (s, t) or (v, nv) == (t, s): -                continue -            can[nv] = 1 -            Q.append((nv, v)) -    d1, z = max((depth2[v], v) for v in range(n) if (can[v])) -    d2 = depth[z] -    # print(d1,d2) -    # if((d1+d2)&1): -    #     d1-=1 -    print((d1 - 1)) +    # x の方が y より近い点 v に対して、その1つ手前で捕まる +    ans = 0 +    for v in range(n): +        if dx[v] < dy[v]: +            ans = max(ans, dy[v] - 1) +    print(ans)