import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def main():
    n, u, v = map(int, input().split())
    u, v = u-1, v-1
    G = [[] for i in range(n)]
    for i in range(n-1):
        a,b = map(int, input().split())
        a,b = a-1,b-1
        G[a].append(b)
        G[b].append(a)

    N = n
    # Euler Tour Technique
    S = []
    FS = [0]*N
    depth = [0]*N
    is_leaf = [0]*N
    def dfs(v, p, d):
        depth[v] = d
        FS[v] = len(S)
        S.append(v)
        f = True
        for w in G[v]:
            if w == p:
                continue
            dfs(w, v, d+1)
            S.append(v)
            f = False
        if f:
            is_leaf[v] = 1

    dfs(v, -1, 0)

    # Sparse Table
    L = len(S)
    lg = [0]*(L + 1)
    for i in range(2, L+1):
        lg[i] = lg[i >> 1] + 1
    st = [None]*(lg[L] + 1)
    st0 = st[0] = S
    b = 1
    for i in range(lg[L]):
        st0 = st[i+1] = [p if depth[p] <= depth[q] else q for p, q in zip(st0, st0[b:])]
        b <<= 1

    # LCA O(1)
    def LCA(u, v):
        x = FS[u]; y = FS[v]
        if x > y:
            x, y = y, x
        l = lg[y - x + 1]
        px = st[l][x]; py = st[l][y - (1 << l) + 1]
        return px if depth[px] <= depth[py] else py

    def dist(u, v):
        return abs(depth[u]-depth[v])

    ans = 0
    for i in range(n):
        if not is_leaf[i]:
            continue
        lca = LCA(u, i)
        if lca == v:
            continue
        if dist(lca, u) >= dist(lca, v):
            continue
        tmp = 0
        d = dist(u, lca) + dist(lca, i)
        if d != 0:
            tmp = 2*d
            aoki = d
        else:
            aoki = 0
        tak = depth[i]
        m = tak-aoki
        if m%2==1:
            tmp += 2*m -1
        else:
            tmp += 2*(m-1)
        ans = max(ans, tmp)
    print(ans//2)

main()