import sys

sys.setrecursionlimit(1000000)



def make_adlist(n):

  adlist = [[] for _ in range(n)]

  for _ in range(n-1):

    a, b = [int(x)-1 for x in input().split()]

    adlist[a] += [b] 

    adlist[b] += [a]

  return adlist



def dfs(adlist, s, dist, d):

  for nxt in adlist[s]:

    if dist[nxt] == -1:

      dist[nxt] = d

      dfs(adlist, nxt, dist, d+1)



def main():

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

  u -= 1

  v -= 1

  adlist = make_adlist(n)

  t_dist = [-1]*n

  t_dist[u] = 0

  dfs(adlist, u, t_dist, 1)

  a_dist = [-1]*n

  a_dist[v] = 0

  dfs(adlist, v, a_dist, 1)

  ans = 0 

  for i in range(n):

    if t_dist[i] < a_dist[i]:

      ans = max(ans, a_dist[i]-1)

  print(ans)



if __name__ == "__main__":

  main()
from collections import deque

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

u -= 1

v -= 1

graph = [[] for _ in range(N)]

for _ in range(N-1):

  a, b = [int(x)-1 for x in input().split()]

  graph[a] += [b]

  graph[b] += [a]



def bfs(s):

  dist = [-1]*N

  q = deque([s])

  dist[s] = 0



  while q:

    u = q.popleft()

    for v in graph[u]:

      if dist[v] == -1:

        dist[v] = dist[u] + 1

        q.append(v)



  return dist



d1 = bfs(u)

d2 = bfs(v)

ans = 0

for i in range(N):

  if d1[i] < d2[i]:

    ans = max(ans, d2[i]-1)



print(ans)



import sys

sys.setrecursionlimit(1000000)


def make_adlist(n):
    adlist = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = [int(x) - 1 for x in input().split()]
        adlist[a] += [b]
        adlist[b] += [a]
    return adlist


def dfs(adlist, s, dist, d):
    for nxt in adlist[s]:
        if dist[nxt] == -1:
            dist[nxt] = d
            dfs(adlist, nxt, dist, d + 1)


def main():
    n, u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    adlist = make_adlist(n)
    t_dist = [-1] * n
    t_dist[u] = 0
    dfs(adlist, u, t_dist, 1)
    a_dist = [-1] * n
    a_dist[v] = 0
    dfs(adlist, v, a_dist, 1)
    ans = 0
    for i in range(n):
        if t_dist[i] < a_dist[i]:
            ans = max(ans, a_dist[i] - 1)
    print(ans)


if __name__ == "__main__":
    main()

from collections import deque

N, u, v = list(map(int, input().split()))
u -= 1
v -= 1
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = [int(x) - 1 for x in input().split()]
    graph[a] += [b]
    graph[b] += [a]


def bfs(s):
    dist = [-1] * N
    q = deque([s])
    dist[s] = 0
    while q:
        u = q.popleft()
        for v in graph[u]:
            if dist[v] == -1:
                dist[v] = dist[u] + 1
                q.append(v)
    return dist


d1 = bfs(u)
d2 = bfs(v)
ans = 0
for i in range(N):
    if d1[i] < d2[i]:
        ans = max(ans, d2[i] - 1)
print(ans)

-import sys +from collections import deque -sys.setrecursionlimit(1000000) +N, u, v = list(map(int, input().split())) +u -= 1 +v -= 1 +graph = [[] for _ in range(N)] +for _ in range(N - 1): +    a, b = [int(x) - 1 for x in input().split()] +    graph[a] += [b] +    graph[b] += [a] -def make_adlist(n): -    adlist = [[] for _ in range(n)] -    for _ in range(n - 1): -        a, b = [int(x) - 1 for x in input().split()] -        adlist[a] += [b] -        adlist[b] += [a] -    return adlist +def bfs(s): +    dist = [-1] * N +    q = deque([s]) +    dist[s] = 0 +    while q: +        u = q.popleft() +        for v in graph[u]: +            if dist[v] == -1: +                dist[v] = dist[u] + 1 +                q.append(v) +    return dist -def dfs(adlist, s, dist, d): -    for nxt in adlist[s]: -        if dist[nxt] == -1: -            dist[nxt] = d -            dfs(adlist, nxt, dist, d + 1) - - -def main(): -    n, u, v = list(map(int, input().split())) -    u -= 1 -    v -= 1 -    adlist = make_adlist(n) -    t_dist = [-1] * n -    t_dist[u] = 0 -    dfs(adlist, u, t_dist, 1) -    a_dist = [-1] * n -    a_dist[v] = 0 -    dfs(adlist, v, a_dist, 1) -    ans = 0 -    for i in range(n): -        if t_dist[i] < a_dist[i]: -            ans = max(ans, a_dist[i] - 1) -    print(ans) - - -if __name__ == "__main__": -    main() +d1 = bfs(u) +d2 = bfs(v) +ans = 0 +for i in range(N): +    if d1[i] < d2[i]: +        ans = max(ans, d2[i] - 1) +print(ans)