n, u, v = gets.split.map(&:to_i)

edge = Array.new(n+1){[]}
(n-1).times do
    a, b = gets.split.map(&:to_i)
    edge[a] << b
    edge[b] << a
end

aoki = Array.new(n+1)
aoki[v] = 0
que = [v]
while x = que.shift
    edge[x].each do |y|
        next if aoki[y]
        aoki[y] = aoki[x] + 1
        que << y
    end
end

taka = Array.new(n+1)
taka[u] = 0
que = [u]
node = []
while x = que.shift
    if edge[x].size == 1
        node << x
    end

    edge[x].each do |y|
        next if taka[y] || taka[x] + 1 >= aoki[y]
        taka[y] = taka[x] + 1
        que << y
    end
end

puts aoki[node.max_by{|e| aoki[e]}] - 1