import sys
input=sys.stdin.readline
n,u,v=map(int,input().split())
edges=list(list(map(int,input().split())) for _ in range(n-1))

counts=list(0 for _ in range(n))
roots=list([] for _ in range(n))
dist_u=list(-1 for _ in range(n))
dist_v=list(-1 for _ in range(n))

dist_u[u-1]=0
dist_v[v-1]=0

for s,t in edges:
    counts[s-1]+=1
    counts[t-1]+=1
    roots[s-1].append(t)
    roots[t-1].append(s)

count=0
while count!=n:
    for node in range(1, n+1):
        if dist_u[node-1]==-1:
            dist_root=max(dist_u[r-1] for r in roots[node-1])
            if dist_root!=-1:
                dist_u[node-1]=dist_root+1
                if dist_v[node-1]!=-1:
                    count+=1
        if dist_v[node-1]==-1:
            dist_root=max(dist_v[r-1] for r in roots[node-1])
            if dist_root!=-1:
                dist_v[node-1]=dist_root+1
                if dist_u[node-1]!=-1:
                    count+=1

longest_path=max(dist_u[node]+dist_v[node] if dist_u[node]<=dist_v[node] else 0 for node in range(n))
print(longest_path//2)