import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,x,y=map(int,input().split())
    x-=1; y-=1

    E=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=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)]
    depth3=[0]*n
    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
            depth3[nv]=depth3[v]+1
            Q.append((nv,v))


    d1,l=max((depth3[v],v) for v in range(n))
    d2=depth2[l]
    # print(path)
    # print(d1,d2)
    ans=min(d1,d2)
    if((d1+d2)&1==0):
        ans-=1

    print(max(0,ans))
resolve()