from collections import deque

INF = 10 ** 9 + 7



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

X = [list(map(int, input().split())) for _ in range(N - 1)]



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

for x, y in X:

    edges[x - 1].append(y - 1)

    edges[y - 1].append(x - 1)

    

def bfs(s):

    d = [INF] * N

    d[s] = 0



    visited = [False] * N

    visited[s] = True

    

    q = deque()

    q.append(s)

    

    while q:

        u = q.popleft()

        for v in edges[u]:

            if visited[v]:

                continue

            

            visited[v] = True

            d[v] = d[u] + 1

            q.append(v)

            

    return d



ans = 0

for x, y in zip(bfs(u - 1), bfs(v - 1)):

    if x <= y:

        ans = max(ans, y - 1)

        

print(ans)

from collections import deque



N, U, V = list(map(int, input().split()))

X = [list(map(int, input().split())) for _ in range(N - 1)]



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

for a, b in X:

    tree[a].append(b)

    tree[b].append(a)



def find_dist(s):

    dist = [-1] * (N + 1)

    dist[s] = 0

    q = deque()

    q.append(s)

    while q:

        u = q.popleft()

        for v in tree[u]:

            if dist[v] >= 0:

                continue

                

            dist[v] = dist[u] + 1

            q.append(v)

            

    return dist





dist_u = find_dist(U)

dist_v = find_dist(V)



ans = 0

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

    if dist_u[i] <= dist_v[i]:

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

        

print(ans)



from collections import deque

INF = 10**9 + 7
N, u, v = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N - 1)]
edges = [[] for _ in range(N)]
for x, y in X:
    edges[x - 1].append(y - 1)
    edges[y - 1].append(x - 1)


def bfs(s):
    d = [INF] * N
    d[s] = 0
    visited = [False] * N
    visited[s] = True
    q = deque()
    q.append(s)
    while q:
        u = q.popleft()
        for v in edges[u]:
            if visited[v]:
                continue
            visited[v] = True
            d[v] = d[u] + 1
            q.append(v)
    return d


ans = 0
for x, y in zip(bfs(u - 1), bfs(v - 1)):
    if x <= y:
        ans = max(ans, y - 1)
print(ans)

from collections import deque

N, U, V = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N + 1)]
for a, b in X:
    tree[a].append(b)
    tree[b].append(a)


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


dist_u = find_dist(U)
dist_v = find_dist(V)
ans = 0
for i in range(1, N + 1):
    if dist_u[i] <= dist_v[i]:
        ans = max(ans, dist_v[i] - 1)
print(ans)

-INF = 10**9 + 7 -N, u, v = list(map(int, input().split())) +N, U, V = list(map(int, input().split())) -edges = [[] for _ in range(N)] -for x, y in X: -    edges[x - 1].append(y - 1) -    edges[y - 1].append(x - 1) +tree = [[] for _ in range(N + 1)] +for a, b in X: +    tree[a].append(b) +    tree[b].append(a) -def bfs(s): -    d = [INF] * N -    d[s] = 0 -    visited = [False] * N -    visited[s] = True +def find_dist(s): +    dist = [-1] * (N + 1) +    dist[s] = 0 -        for v in edges[u]: -            if visited[v]: +        for v in tree[u]: +            if dist[v] >= 0: -            visited[v] = True -            d[v] = d[u] + 1 +            dist[v] = dist[u] + 1 -    return d +    return dist +dist_u = find_dist(U) +dist_v = find_dist(V) -for x, y in zip(bfs(u - 1), bfs(v - 1)): -    if x <= y: -        ans = max(ans, y - 1) +for i in range(1, N + 1): +    if dist_u[i] <= dist_v[i]: +        ans = max(ans, dist_v[i] - 1)