from math import ceil
N, u, v = map(lambda x: int(x)-1, input().split())
N += 1
edges = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N-1)]
adj = [[] for _ in range(N)]
for a, b in edges:
    adj[a].append(b)
    adj[b].append(a)

# bfs from v
dist_from_v = [-1]*N
dist_from_v[v] = 0
Q = [v]
while Q:
    tmp = []
    for cur in Q:
        for next in adj[cur]:
            if dist_from_v[next] == -1:
                dist_from_v[next] = dist_from_v[cur]+1
                tmp.append(next)
    Q = tmp

dst_u = -1
# bfs from u
dist_from_u = [-1]*N
dist_from_u[u] = 0
Q = [u]
while Q:
    tmp = []
    for cur in Q:
        for next in adj[cur]:
            if dist_from_u[next] == -1:
                if dist_from_u[cur]+1 >= dist_from_v[next]:
                    # print("update")
                    cut = (cur, next)
                else:
                    dist_from_u[next] = dist_from_u[cur]+1
                    tmp.append(next)
    Q = tmp


dst_u = dist_from_u.index(max(dist_from_u))
dist_u_dst = max(dist_from_u)
dist_v_dst = dist_from_v[dst_u]
# print(dist_from_v)
# print(dist_from_u)
# print(cut)
assert dist_u_dst < dist_v_dst

if dist_v_dst % 2 == 0:
    ans = dist_v_dst-1
else:
    ans = dist_v_dst-2
print(ans)
