# -*- coding: utf-8 -*-

def solve():
    N, u, v = map(int, input().split())
    G = [[] for _ in range(N+1)]
    dv = [float('inf') for _ in range(N+1)]
    du = [float('inf') for _ in range(N+1)]
    d = [float('inf') for _ in range(N+1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        G[a].append(b)
        G[b].append(a)
    Q = [v]
    dv[v]=0
    while Q:
        n = Q.pop()
        for p in G[n]:
            if dv[p] == float('inf'):
                dv[p] = dv[n]+1
                Q.append(p)
    Q = [u]
    du[u]=0
    while Q:
        n = Q.pop()
        for p in G[n]:
            if du[p] == float('inf'):
                du[p] = du[n]+1
                Q.append(p)

    Q = [u]
    d[u]=0
    while Q:
        n = Q.pop()
        for p in G[n]:
            if d[p] == float('inf') and du[p] < dv[p]:
                d[p] = d[n]+1
                Q.append(p)
    D = min(a for a,b in zip(du,dv) if a==b)
    if D==float('inf'):
        D = 0
    d_max = max(a for a in d if a!=float('inf'))

    res = max(D, d_max)
    return str(res)

if __name__ == '__main__':
    print(solve())
