import collections

import sys

sys.setrecursionlimit(10**7)



def dfs(u):

  for v in g[u]:

    if checked[v]==1:

      continue

    else:

      checked[v]=1

      depth2[u]=max(depth2[u],dfs(v)+1)

  return depth2[u]



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

g=[[] for _ in range(n+1)]

for _ in range(n-1):

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

  g[a].append(b)

  g[b].append(a)

depth=[0]*(n+1)

checked=[0]*(n+1)

checked[v]=1

q=collections.deque()

q.append((v,0))

while 1:

  if len(q)==0:

    break

  tu,d=q.popleft()

  checked[tu]=1

  depth[tu]=d

  for tv in g[tu]:

    if checked[tv]!=1:

      checked[tv]=1

      q.append((tv,d+1))

moves=(depth[u]-1)//2

depth2=[0]*(n+1)

checked=[0]*(n+1)

checked[v]=1

dfs(v)

checked=[0]*(n+1)

checked[u]=1

q=collections.deque()

q.append((u,0))

cand=[]

while 1:

  if len(q)==0:

    break

  tu,d=q.popleft()

  if d==moves:

    cand.append(tu)

  checked[tu]=1

  for tv in g[tu]:

    if checked[tv]!=1:

      checked[tv]=1

      q.append((tv,d+1))

md=0

for i in cand:

  md=max(md,depth2[i])

if depth[u]%2!=0:

  ans=moves+md

else:

  ans=moves+md+1

print(ans)
import collections



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

g=[[] for _ in range(n+1)]

for _ in range(n-1):

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

  g[a].append(b)

  g[b].append(a)

q=collections.deque()

q.append((v,0))

checked=[0]*(n+1)

dist1=[0]*(n+1)

while len(q)!=0:

  tv,td=q.popleft()

  checked[tv]=1

  dist1[tv]=td

  for tu in g[tv]:

    if checked[tu]==1:

      continue

    q.append((tu,td+1))

q=collections.deque()

q.append((u,0))

checked=[0]*(n+1)

dist2=[0]*(n+1)

while len(q)!=0:

  tv,td=q.popleft()

  checked[tv]=1

  dist2[tv]=td

  for tu in g[tv]:

    if checked[tu]==1:

      continue

    q.append((tu,td+1))

ans=0

for tv in range(1,n+1):

  if dist1[tv]>dist2[tv]:

    ans=max(ans,dist1[tv]-1)

print(ans)
import collections
import sys

sys.setrecursionlimit(10**7)


def dfs(u):
    for v in g[u]:
        if checked[v] == 1:
            continue
        else:
            checked[v] = 1
            depth2[u] = max(depth2[u], dfs(v) + 1)
    return depth2[u]


n, u, v = list(map(int, input().split()))
g = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    g[a].append(b)
    g[b].append(a)
depth = [0] * (n + 1)
checked = [0] * (n + 1)
checked[v] = 1
q = collections.deque()
q.append((v, 0))
while 1:
    if len(q) == 0:
        break
    tu, d = q.popleft()
    checked[tu] = 1
    depth[tu] = d
    for tv in g[tu]:
        if checked[tv] != 1:
            checked[tv] = 1
            q.append((tv, d + 1))
moves = (depth[u] - 1) // 2
depth2 = [0] * (n + 1)
checked = [0] * (n + 1)
checked[v] = 1
dfs(v)
checked = [0] * (n + 1)
checked[u] = 1
q = collections.deque()
q.append((u, 0))
cand = []
while 1:
    if len(q) == 0:
        break
    tu, d = q.popleft()
    if d == moves:
        cand.append(tu)
    checked[tu] = 1
    for tv in g[tu]:
        if checked[tv] != 1:
            checked[tv] = 1
            q.append((tv, d + 1))
md = 0
for i in cand:
    md = max(md, depth2[i])
if depth[u] % 2 != 0:
    ans = moves + md
else:
    ans = moves + md + 1
print(ans)

import collections

n, u, v = list(map(int, input().split()))
g = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    g[a].append(b)
    g[b].append(a)
q = collections.deque()
q.append((v, 0))
checked = [0] * (n + 1)
dist1 = [0] * (n + 1)
while len(q) != 0:
    tv, td = q.popleft()
    checked[tv] = 1
    dist1[tv] = td
    for tu in g[tv]:
        if checked[tu] == 1:
            continue
        q.append((tu, td + 1))
q = collections.deque()
q.append((u, 0))
checked = [0] * (n + 1)
dist2 = [0] * (n + 1)
while len(q) != 0:
    tv, td = q.popleft()
    checked[tv] = 1
    dist2[tv] = td
    for tu in g[tv]:
        if checked[tu] == 1:
            continue
        q.append((tu, td + 1))
ans = 0
for tv in range(1, n + 1):
    if dist1[tv] > dist2[tv]:
        ans = max(ans, dist1[tv] - 1)
print(ans)

-import sys - -sys.setrecursionlimit(10**7) - - -def dfs(u): -    for v in g[u]: -        if checked[v] == 1: -            continue -        else: -            checked[v] = 1 -            depth2[u] = max(depth2[u], dfs(v) + 1) -    return depth2[u] - -depth = [0] * (n + 1) -checked = [0] * (n + 1) -checked[v] = 1 -while 1: -    if len(q) == 0: -        break -    tu, d = q.popleft() -    checked[tu] = 1 -    depth[tu] = d -    for tv in g[tu]: -        if checked[tv] != 1: -            checked[tv] = 1 -            q.append((tv, d + 1)) -moves = (depth[u] - 1) // 2 -depth2 = [0] * (n + 1) -checked[v] = 1 -dfs(v) -checked = [0] * (n + 1) -checked[u] = 1 +dist1 = [0] * (n + 1) +while len(q) != 0: +    tv, td = q.popleft() +    checked[tv] = 1 +    dist1[tv] = td +    for tu in g[tv]: +        if checked[tu] == 1: +            continue +        q.append((tu, td + 1)) -cand = [] -while 1: -    if len(q) == 0: -        break -    tu, d = q.popleft() -    if d == moves: -        cand.append(tu) -    checked[tu] = 1 -    for tv in g[tu]: -        if checked[tv] != 1: -            checked[tv] = 1 -            q.append((tv, d + 1)) -md = 0 -for i in cand: -    md = max(md, depth2[i]) -if depth[u] % 2 != 0: -    ans = moves + md -else: -    ans = moves + md + 1 +checked = [0] * (n + 1) +dist2 = [0] * (n + 1) +while len(q) != 0: +    tv, td = q.popleft() +    checked[tv] = 1 +    dist2[tv] = td +    for tu in g[tv]: +        if checked[tu] == 1: +            continue +        q.append((tu, td + 1)) +ans = 0 +for tv in range(1, n + 1): +    if dist1[tv] > dist2[tv]: +        ans = max(ans, dist1[tv] - 1)