N, u, v = (int(i) for i in input().split())
adj=[]
for i in range(N+1):adj.append([])
for i in range(N-1):
	a,b = map(int,input().split())
	adj[a]+=[b]
	adj[b]+=[a]
	
prof = [0]*(N+1)
haut = [0]*(N+1)
parent = [-1]*(N+1)

def enraciner(sommet):
	for s in adj[sommet]:
		if s!=parent[sommet]:
			parent[s] = sommet
			prof[s] = 1+prof[sommet]
			enraciner(s)
	haut[sommet] = 1
	if parent[sommet]==-1:haut[sommet]+=max(haut[s]for s in adj[sommet] if s!=parent[sommet])
	elif len(adj[sommet]) >1 : haut[sommet]+= max(haut[s]for s in adj[sommet] if s!=parent[sommet])

enraciner(v)

# ~ print("parent",parent)
# ~ print("haut",haut)
# ~ print("prof",prof)

ans = 0

#montee
pu = prof[u]
pv = prof[v]
m = (pu - pv -1)//2
pu-=m
pv+=m
# ~ print("m",m)
ans+=m
for i in range(m):
	u = parent[u]

mx = 0
if len(adj[u])>1:mx = max(haut[i] for i in adj[u] if i!= parent[u])
# ~ print("mx",mx)
ans+= mx

last = (pu-pv)//2
# ~ print("last",last)
ans+=last

print(ans)

