import copy

import sys

sys.setrecursionlimit(100000)

input = sys.stdin.readline



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

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

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

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

vs = set()

r = {}



def it(v, p, depth, ps):

    for u in d[v]:

        if u == p:

            continue

        dps[u] = depth

        if u == V:

            r["p"] = copy.deepcopy(ps)

            continue

        ps.add(u)

        it(u, v, depth+1,ps)

        ps.remove(u)

        vs.add(u)



def it2(v, p, depth):

    for u in d[v]:

        if u == p:

            continue

        if u not in vs:

            continue

        if dps[v] >= depth-1 and u not in r["p"]:

            continue

        dpss[u] = depth

        it2(u, v, depth+1)







for _ in range(N-1):

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

    d[a].add(b)

    d[b].add(a)



vs.add(U)

it(U, -1, 1, set([U]))

it2(V, -1, 1)

print((max(dpss)-1))

import sys

input = sys.stdin.readline

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

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

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

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

oks = set()



def it(v):

    stack = [v]

    vs = set()

    path = []

    while True:

        if not len(stack):

            break

        v = stack.pop()

        if v > 0:

            path.append(v)

            vs.add(v)

            for u in d[v]:

                if u in vs:

                    continue

                if u == V:

                    r = path[:]

                    continue

                dps[u] = dps[v] + 1

                oks.add(u)

                stack.append(-v)

                stack.append(u)

        else:

            path.pop()

    return r



def it2(v, path):

    stack = [v]

    vs = set()

    while True:

        if not len(stack):

            break

        v = stack.pop()

        vs.add(v)

        for u in d[v]:

            if u in vs:

                continue

            if u not in oks:

                continue

            if dps[v] >= dpss[v] and u not in path:

                continue

            dpss[u] = dpss[v] + 1

            stack.append(u)



for _ in range(N-1):

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

    d[a].add(b)

    d[b].add(a)



oks.add(U)

path = set(it(U))

it2(V, path)

print((max(dpss)-1))

import copy
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
N, U, V = list(map(int, input().split()))
d = [set() for _ in range(N + 1)]
dps = [0 for _ in range(N + 1)]
dpss = [0 for _ in range(N + 1)]
vs = set()
r = {}


def it(v, p, depth, ps):
    for u in d[v]:
        if u == p:
            continue
        dps[u] = depth
        if u == V:
            r["p"] = copy.deepcopy(ps)
            continue
        ps.add(u)
        it(u, v, depth + 1, ps)
        ps.remove(u)
        vs.add(u)


def it2(v, p, depth):
    for u in d[v]:
        if u == p:
            continue
        if u not in vs:
            continue
        if dps[v] >= depth - 1 and u not in r["p"]:
            continue
        dpss[u] = depth
        it2(u, v, depth + 1)


for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    d[a].add(b)
    d[b].add(a)
vs.add(U)
it(U, -1, 1, set([U]))
it2(V, -1, 1)
print((max(dpss) - 1))

import sys

input = sys.stdin.readline
N, U, V = list(map(int, input().split()))
d = [set() for _ in range(N + 1)]
dps = [0 for _ in range(N + 1)]
dpss = [0 for _ in range(N + 1)]
oks = set()


def it(v):
    stack = [v]
    vs = set()
    path = []
    while True:
        if not len(stack):
            break
        v = stack.pop()
        if v > 0:
            path.append(v)
            vs.add(v)
            for u in d[v]:
                if u in vs:
                    continue
                if u == V:
                    r = path[:]
                    continue
                dps[u] = dps[v] + 1
                oks.add(u)
                stack.append(-v)
                stack.append(u)
        else:
            path.pop()
    return r


def it2(v, path):
    stack = [v]
    vs = set()
    while True:
        if not len(stack):
            break
        v = stack.pop()
        vs.add(v)
        for u in d[v]:
            if u in vs:
                continue
            if u not in oks:
                continue
            if dps[v] >= dpss[v] and u not in path:
                continue
            dpss[u] = dpss[v] + 1
            stack.append(u)


for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    d[a].add(b)
    d[b].add(a)
oks.add(U)
path = set(it(U))
it2(V, path)
print((max(dpss) - 1))

-import copy -sys.setrecursionlimit(100000) -vs = set() -r = {} +oks = set() -def it(v, p, depth, ps): -    for u in d[v]: -        if u == p: -            continue -        dps[u] = depth -        if u == V: -            r["p"] = copy.deepcopy(ps) -            continue -        ps.add(u) -        it(u, v, depth + 1, ps) -        ps.remove(u) -        vs.add(u) +def it(v): +    stack = [v] +    vs = set() +    path = [] +    while True: +        if not len(stack): +            break +        v = stack.pop() +        if v > 0: +            path.append(v) +            vs.add(v) +            for u in d[v]: +                if u in vs: +                    continue +                if u == V: +                    r = path[:] +                    continue +                dps[u] = dps[v] + 1 +                oks.add(u) +                stack.append(-v) +                stack.append(u) +        else: +            path.pop() +    return r -def it2(v, p, depth): -    for u in d[v]: -        if u == p: -            continue -        if u not in vs: -            continue -        if dps[v] >= depth - 1 and u not in r["p"]: -            continue -        dpss[u] = depth -        it2(u, v, depth + 1) +def it2(v, path): +    stack = [v] +    vs = set() +    while True: +        if not len(stack): +            break +        v = stack.pop() +        vs.add(v) +        for u in d[v]: +            if u in vs: +                continue +            if u not in oks: +                continue +            if dps[v] >= dpss[v] and u not in path: +                continue +            dpss[u] = dpss[v] + 1 +            stack.append(u) -vs.add(U) -it(U, -1, 1, set([U])) -it2(V, -1, 1) +oks.add(U) +path = set(it(U)) +it2(V, path)