import sys
import copy
input = sys.stdin.readline
import numpy as np
N, U, V = [int(x) for x in input().split()]
n = N
G_1 = [[] for _ in range(N)]
G = G_1[0:]
for _ in range(N-1):
    A, B = [int(x) for x in input().split()]
    G[A-1].append(B-1)
    G[B-1].append(A-1)

from collections import deque
d = [-1] * n
color = ["WHITE"] * n
queue = []
queue = deque(queue)

def bfs(u):
    color[u-1] = "GRAY"
    d[u-1] = 0
    queue.append(u-1)
    while len(queue) > 0:
        u = queue.popleft()
        if len(G[u]) == 0:
            color[u] = "BLACK"
        else:
            for u_next in G[u]:
                if color[u_next] == "WHITE":
                    d[u_next] = d[u] + 1
                    color[u_next] = "GRAY"
                    queue.append(u_next)
                G[u] = 0
            color[u] == "BLACK"
bfs(U)
a = d[0:]
G = G_1[0:]
d = [-1] * n
color = ["WHITE"] * n
queue = []
queue = deque(queue)
bfs(V)
t = d[0:]
a = np.array(a)
t = np.array(t)
ans = a[a<t].max()
print(ans)