from collections import deque
N,u,v=map(int,input().split())
u-=1;v-=1
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    a-=1;b-=1
    G[a].append(b)
    G[b].append(a)
q=deque([])
q.append(u)
dist=[-1 for i in range(N)]
parents=[-1 for i in range(N)]
dist[u]=0
while(len(q)>0):
    r=q.popleft()
    for p in G[r]:
        if dist[p]!=-1:
            continue
        dist[p]=dist[r]+1
        parents[p]=r
        q.append(p)
L=[v]
x=v
while(1):
    if x==u:
        break
    L.append(parents[x])
    x=parents[x]
#print(parents)
#print(L)
M=len(L)
x=L[M//2-1]
X=M//2-1
dist2=[-1 for i in range(N)]
dist2[x]=0
q=deque([])
q.append(x)
while(len(q)>0):
    r=q.popleft()
    for p in G[r]:
        if dist2[p]!=-1:
            continue
        dist2[p]=dist2[r]+1
        q.append(p)
Y=max(dist2)-1
print(X+Y)