parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function root(uf::Array{Int,1},x)
	s=x
	while uf[s]>0
		s=uf[s]
	end
	s
end
function same(uf::Array{Int,1},x,y)
	root(uf,x)==root(uf,y)?true:false
end
function unite(uf::Array{Int,1},x,y)
	l = root(uf,x)
	r = root(uf,y)
	if l < r
		uf[l] += uf[r]
		uf[r] = l
	elseif l > r
		uf[r] += uf[l]
		uf[l] = r
	end
end

function eval(a::Tuple{Int,Int},b::Tuple{Int,Int})
	if a[2]<b[2]
		1
	elseif a[2]==b[2]
		0
	else
		-1
	end
end

function hpush(h::Array{Tuple{Int,Int},1},x::Tuple{Int,Int})
	push!(h,x)
	if length(h) > 1
		l = length(h)
		k = l>>1
		while eval(x,h[k])==1&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(k>>1,1)
			l = l>>1
		end
	end
end

function hpop(h::Array{Tuple{Int,Int},1})
	x = h[1]
	z = pop!(h)
	if !isempty(h)
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>l
				break
			elseif 2*k+1>l
				if eval(h[2*k],z)>=0
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if eval(z,h[2*k])>=0&&eval(z,h[2*k+1])>=0
					break
				else
					t = eval(h[2*k],h[2*k+1])>=0?2*k:2*k+1
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end

function main()
	n,gu,gv = readline() |> split |> parseMap
	e = [Int[] for i in 1:n]
	el = zeros(Int,n-1,2)
	for i in 1:n-1
		a,b = readline() |> split |> parseMap
		push!(e[a],b)
		push!(e[b],a)
		el[i,:] = [a,b]
	end
	dis = -ones(Int,n)
	h = Array{Tuple{Int,Int},1}()
	push!(h,(gv,0))
	while !isempty(h)
		v,w = hpop(h)
		dis[v] = dis[v]<0?w:min(dis[v],w)
		for i in 1:length(e[v])
			if dis[e[v][i]]<0　|| dis[e[v][i]]>w+1
				dis[e[v][i]] = w+1
				hpush(h,(e[v][i],w+1))
			end
		end
	end

	hunt = dis[gu]>>2
	ng = [Int[] for i in 1:n]
	for i in 1:n-1
		if dis[el[i,1]]>hunt&&dis[el[i,2]]>hunt
			push!(ng[el[i,1]],el[i,2])
			push!(ng[el[i,2]],el[i,1])
		end
	end
	disu = -ones(Int,n)
	h = Array{Tuple{Int,Int},1}()
	push!(h,(gu,0))
	while !isempty(h)
		v,w = hpop(h)
		disu[v] = disu[v]<0?w:min(disu[v],w)
		for i in 1:length(ng[v])
			if disu[ng[v][i]]<0　|| disu[ng[v][i]]>w+1
				disu[ng[v][i]] = w+1
				hpush(h,(ng[v][i],w+1))
			end
		end
	end
	ep = 0
	ev = 0
	for i in 1:n
		if disu[i]>-1&&dis[i]>ev
			ep = i
			ev = dis[i]
		end
	end
	z = disu[ep]

	println(ev-1)
end

main()