def main():
    n, u, v = map(int, raw_input().split())
    u -= 1
    v -= 1
    tree = {i: [] for i in xrange(n)}
    for _ in xrange(n - 1):
        a, b = map(int, raw_input().split())
        a -= 1
        b -= 1
        tree[a].append(b)
        tree[b].append(a)
    dist = [None] * n
    dist[v] = 0
    stack = [[v, 0]]
    while stack:
        node, d = stack.pop()
        d += 1
        for nex in tree[node]:
            if dist[nex] is None:
                dist[nex] = d
                stack.append([nex, d])
    
    stack = [[u, 0]]
    visited = [False] * n
    visited[u] = True
    best = 0
    while stack:
        node, d = stack.pop()
        d += 1
        for nex in tree[node]:
            if dist[nex] >= d and not visited[nex]:
                if dist[nex] > d:
                    stack.append([nex, d])
                visited[nex] = True
                if dist[nex] < dist[node]:
                    best = max(best, dist[node] - 1)
                else:
                    best = max(best, dist[node])
    print best


main()
