n, u, v = map(int, input().split())
V = [ [] for _ in range(n + 1) ]
for _ in range(n - 1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

t, a = 0, 0
tpos, apos = {u:0}, {v:0}

amin = float("-inf")
while len(tpos) > 0:
    t_new = dict() # T moves                                                                                                                            
    for k, v in tpos.items():
        for dst in V[k]:
            t_new[dst] = max(t_new.get(dst, 0), v + 1)
            if dst in apos:
                amin = max(amin, apos[dst])
                del t_new[dst]

    a_new = dict() # A moves                                                                                                                            
    for k, v in apos.items():
        for dst in V[k]:
            a_new[dst] = max(a_new.get(dst, 0), v + 1)
            if dst in t_new:
                amin = max(amin, a_new[dst])
                del t_new[dst]

    tpos = t_new
    apos = a_new

print(amin)
