from collections import deque

INFTY = 10**6

N,u,v = list(map(int,input().split()))

G = {i:[] for i in range(1,N+1)}

for _ in range(N-1):

    a,b = list(map(int,input().split()))

    G[a].append(b)

    G[b].append(a)

du = [INFTY for _ in range(N+1)]

du[u] = 0

que = deque([(0,u)])

hist = [0 for _ in range(N+1)]

hist[u] = 1

while que:

    c,i = que.popleft()

    for j in G[i]:

        if hist[j]==0:

            que.append((c+1,j))

            du[j] = c+1

            hist[j] = 1

dv = [INFTY for _ in range(N+1)]

dv[v] = 0

que = deque([(0,v)])

hist = [0 for _ in range(N+1)]

hist[v] = 1

while que:

    c,i = que.popleft()

    for j in G[i]:

        if hist[j]==0:

            que.append((c+1,j))

            dv[j] = c+1

            hist[j] = 1

cmax = 0

for i in range(1,N+1):

    if du[i]<dv[i]:

        cmax = max(cmax,dv[i])

print((cmax-1))
from collections import deque

N,u,v = list(map(int,input().split()))

G = {i:[] for i in range(1,N+1)}

for _ in range(N-1):

    a,b = list(map(int,input().split()))

    G[a].append(b)

    G[b].append(a)

distT = [0 for _ in range(N+1)]

heap = deque([(u,0)])

distT[u] = 0

hist = [0 for _ in range(N+1)]

hist[u] = 1

while heap:

    x,d = heap.popleft()

    for y in G[x]:

        if hist[y]==0:

            distT[y] = d+1

            heap.append((y,d+1))

            hist[y]=1

heap = deque([(v,0)])

distA = [0 for _ in range(N+1)]

heap = deque([(v,0)])

distA[v] = 0

hist = [0 for _ in range(N+1)]

hist[v] = 1

while heap:

    x,d = heap.popleft()

    for y in G[x]:

        if hist[y]==0:

            distA[y]=d+1

            heap.append((y,d+1))

            hist[y] = 1

cmax = 0

for i in range(1,N+1):

    if distT[i]<=distA[i] and distA[i]>cmax:

        cmax = distA[i]

print((cmax-1))
from collections import deque

INFTY = 10**6
N, u, v = list(map(int, input().split()))
G = {i: [] for i in range(1, N + 1)}
for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    G[a].append(b)
    G[b].append(a)
du = [INFTY for _ in range(N + 1)]
du[u] = 0
que = deque([(0, u)])
hist = [0 for _ in range(N + 1)]
hist[u] = 1
while que:
    c, i = que.popleft()
    for j in G[i]:
        if hist[j] == 0:
            que.append((c + 1, j))
            du[j] = c + 1
            hist[j] = 1
dv = [INFTY for _ in range(N + 1)]
dv[v] = 0
que = deque([(0, v)])
hist = [0 for _ in range(N + 1)]
hist[v] = 1
while que:
    c, i = que.popleft()
    for j in G[i]:
        if hist[j] == 0:
            que.append((c + 1, j))
            dv[j] = c + 1
            hist[j] = 1
cmax = 0
for i in range(1, N + 1):
    if du[i] < dv[i]:
        cmax = max(cmax, dv[i])
print((cmax - 1))

from collections import deque

N, u, v = list(map(int, input().split()))
G = {i: [] for i in range(1, N + 1)}
for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    G[a].append(b)
    G[b].append(a)
distT = [0 for _ in range(N + 1)]
heap = deque([(u, 0)])
distT[u] = 0
hist = [0 for _ in range(N + 1)]
hist[u] = 1
while heap:
    x, d = heap.popleft()
    for y in G[x]:
        if hist[y] == 0:
            distT[y] = d + 1
            heap.append((y, d + 1))
            hist[y] = 1
heap = deque([(v, 0)])
distA = [0 for _ in range(N + 1)]
heap = deque([(v, 0)])
distA[v] = 0
hist = [0 for _ in range(N + 1)]
hist[v] = 1
while heap:
    x, d = heap.popleft()
    for y in G[x]:
        if hist[y] == 0:
            distA[y] = d + 1
            heap.append((y, d + 1))
            hist[y] = 1
cmax = 0
for i in range(1, N + 1):
    if distT[i] <= distA[i] and distA[i] > cmax:
        cmax = distA[i]
print((cmax - 1))

-INFTY = 10**6 -du = [INFTY for _ in range(N + 1)] -du[u] = 0 -que = deque([(0, u)]) +distT = [0 for _ in range(N + 1)] +heap = deque([(u, 0)]) +distT[u] = 0 -while que: -    c, i = que.popleft() -    for j in G[i]: -        if hist[j] == 0: -            que.append((c + 1, j)) -            du[j] = c + 1 -            hist[j] = 1 -dv = [INFTY for _ in range(N + 1)] -dv[v] = 0 -que = deque([(0, v)]) +while heap: +    x, d = heap.popleft() +    for y in G[x]: +        if hist[y] == 0: +            distT[y] = d + 1 +            heap.append((y, d + 1)) +            hist[y] = 1 +heap = deque([(v, 0)]) +distA = [0 for _ in range(N + 1)] +heap = deque([(v, 0)]) +distA[v] = 0 -while que: -    c, i = que.popleft() -    for j in G[i]: -        if hist[j] == 0: -            que.append((c + 1, j)) -            dv[j] = c + 1 -            hist[j] = 1 +while heap: +    x, d = heap.popleft() +    for y in G[x]: +        if hist[y] == 0: +            distA[y] = d + 1 +            heap.append((y, d + 1)) +            hist[y] = 1 -    if du[i] < dv[i]: -        cmax = max(cmax, dv[i]) +    if distT[i] <= distA[i] and distA[i] > cmax: +        cmax = distA[i]