from collections import deque

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

U -= 1

V -= 1

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

for _ in range(N - 1):

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

    a -= 1

    b -= 1

    tree[a].append(b)

    tree[b].append(a)





def get_rank(v):

    rank = [-1] * N

    next_v = deque([v])

    rank[v] = 0

    while next_v:

        node = next_v.popleft()

        r = rank[node]

        for i in tree[node]:

            if rank[i] != -1:

                continue

            rank[i] = r + 1

            next_v.append(i)

    return rank





takahashi = get_rank(U)

aoki = get_rank(V)

ans = 0

for x, y in zip(takahashi, aoki):

    if x <= y:

        ans = max(ans, y-1)



print(ans)
import sys

input = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)



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

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

for _ in range(N - 1):

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

    edge[a].append(b)

    edge[b].append(a)





def calc_dist(s):

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

    dist[s] = 0

    node = [s]

    while node:

        s = node.pop()

        d = dist[s]

        for t in edge[s]:

            if dist[t] != -1:

                continue

            dist[t] = d + 1

            node.append(t)

    return dist[1:]





taka = calc_dist(u)

aoki = calc_dist(v)

ans = 0



for x, y in zip(taka, aoki):

    if x <= y:

        ans = max(ans, y - 1)



print(ans)

from collections import deque

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


def get_rank(v):
    rank = [-1] * N
    next_v = deque([v])
    rank[v] = 0
    while next_v:
        node = next_v.popleft()
        r = rank[node]
        for i in tree[node]:
            if rank[i] != -1:
                continue
            rank[i] = r + 1
            next_v.append(i)
    return rank


takahashi = get_rank(U)
aoki = get_rank(V)
ans = 0
for x, y in zip(takahashi, aoki):
    if x <= y:
        ans = max(ans, y - 1)
print(ans)

import sys

input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
N, u, v = list(map(int, input().split()))
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    edge[a].append(b)
    edge[b].append(a)


def calc_dist(s):
    dist = [-1] * (N + 1)
    dist[s] = 0
    node = [s]
    while node:
        s = node.pop()
        d = dist[s]
        for t in edge[s]:
            if dist[t] != -1:
                continue
            dist[t] = d + 1
            node.append(t)
    return dist[1:]


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

-from collections import deque +import sys -N, U, V = list(map(int, input().split())) -U -= 1 -V -= 1 -tree = [[] for _ in range(N)] +input = sys.stdin.buffer.readline +sys.setrecursionlimit(10**7) +N, u, v = list(map(int, input().split())) +edge = [[] for _ in range(N + 1)] -    a -= 1 -    b -= 1 -    tree[a].append(b) -    tree[b].append(a) +    edge[a].append(b) +    edge[b].append(a) -def get_rank(v): -    rank = [-1] * N -    next_v = deque([v]) -    rank[v] = 0 -    while next_v: -        node = next_v.popleft() -        r = rank[node] -        for i in tree[node]: -            if rank[i] != -1: +def calc_dist(s): +    dist = [-1] * (N + 1) +    dist[s] = 0 +    node = [s] +    while node: +        s = node.pop() +        d = dist[s] +        for t in edge[s]: +            if dist[t] != -1: -            rank[i] = r + 1 -            next_v.append(i) -    return rank +            dist[t] = d + 1 +            node.append(t) +    return dist[1:] -takahashi = get_rank(U) -aoki = get_rank(V) +taka = calc_dist(u) +aoki = calc_dist(v) -for x, y in zip(takahashi, aoki): +for x, y in zip(taka, aoki):