import sys

input = sys.stdin.readline

def bfs(v):
    dist = [None] * N
    
    q = [(v, 0)]
    
    while q:
        v, c = q.pop(0)
        dist[v] = c
        
        for u in G[v]:
            if not dist[u] is None: continue
            q.append((u, c+1))
    return dist

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)
    
        
v_dist = bfs(v)
u_dist = bfs(u)

n = 0
m = float('inf')

for v, u in zip(v_dist, u_dist):
    if v == u: m = min(m, v)
    elif v > u: n = max(n, u)
        
if m == float('inf'): print(n)
else: print(max(n, m))

