import sys
input = sys.stdin.readline

# 再帰上限を引き上げる
sys.setrecursionlimit(10**6)




n,u,v = (int(x) for x in input().split())

u,v = u-1,v-1

a = [[] for i in range(n)]

for i in range(n-1):
	# 配列indexは0開始だからinputは-1
	l,m = (int(x)-1 for x in input().split())
	a[l].append(m)
	a[m].append(l)

# v視点のdistを調べる
dist_u = [0]*n
dist_v = [0]*n

# G:graph, cr:current node, seen:is seen?, dist:out;each distance
def dfs_u(cr,seen):
	seen[cr] = 1
	for i in G[cr]: #G[cr]から行ける各頂点へ
		if seen[i] == 0: #まだ通っていなかったら
			dist_u[i] = dist_u[cr]+1
			dfs_u(i,seen)
# G:graph, cr:current node, seen:is seen?, dist:out;each distance
def dfs_v(cr,seen):
	seen[cr] = 1
	for i in G[cr]: #G[cr]から行ける各頂点へ
		if seen[i] == 0: #まだ通っていなかったら
			dist_v[i] = dist_v[cr]+1
			dfs_v(i,seen)

dfs_u(u,[0]*n)
# u視点のdistを調べる
dfs_v(v,[0]*n)

for i in range(n):
	if dist_u[i] >= dist_v[i]: # vが追いつける距離なら
		dist_u[i] = -1

print(dist_v[dist_u.index(max(dist_u))] - 1)