from collections import deque

n,u,v=map(int,input().split())
list=[list(map(int,input().split())) for i in range(n-1)]

tree=[[] for i in range(n)]
for i in list:
  tree[i[0]-1].append(i[1]-1)
  tree[i[1]-1].append(i[0]-1)

dist=[-1 for i in range(n)]
dist[u-1]=0

que=deque()
que.append(u-1)
while que:
    x=que.popleft()
    if x==v-1:
        print(dist[x]-1)
        break
    for p in tree[x]:
        if dist[p]==-1:
            que.append(p)
            dist[p]=dist[x]+1