# -*- coding: utf-8 -*-

import bisect

import heapq

import math

import random

import sys

from collections import Counter, defaultdict, deque

from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal

from functools import lru_cache, reduce

from itertools import combinations, combinations_with_replacement, product, permutations

from operator import add, mul, sub



sys.setrecursionlimit(100000)

input = sys.stdin.readline

INF = 2**62-1



def read_int():

    return int(input())





def read_int_n():

    return list(map(int, input().split()))





def read_float():

    return float(input())





def read_float_n():

    return list(map(float, input().split()))





def read_str():

    return input().strip()





def read_str_n():

    return list(map(str, input().split()))





def error_print(*args):

    print(*args, file=sys.stderr)





def mt(f):

    import time



    def wrap(*args, **kwargs):

        s = time.time()

        ret = f(*args, **kwargs)

        e = time.time()



        error_print(e - s, 'sec')

        return ret



    return wrap





@mt

def slv(N, u, v, AB):

    ans = 0

    g = defaultdict(set)

    for a, b in AB:

        g[a].add(b)

        g[b].add(a)





    def f(start):

        s = [(start, 0)]

        d = {}

        d[start] = 0

        while s:

            c, l = s.pop()

            for n in g[c]:

                if n not in d:

                    s.append((n, l+1))

                    d[n] = l+1

        return d



    vd = f(v)

    t = u

    a = v

    s = [(t, 0)]

    d = {}

    d[t] = 0

    while s:

        u, l = s.pop()

        for v in g[u]:

            if v not in d and l + 1 < vd[v]:

                s.append((v, l+1))

                tmp = vd[v] - (l+1)

                tmp = (tmp//2) * 2

                d[v] = tmp + (l+1)



    d[t] = (vd[t] // 2) * 2

    dest = (0, -1)

    for k, v in d.items():

        dest = max(dest, (v, k))



    ans = dest[0]

    # error_print(dest)

    # error_print(d)

    # error_print(vd)

    if vd[dest[1]] == dest[0]:

        ans -= 1

    return ans





def main():

    N, u, v = read_int_n()

    AB = [read_int_n() for _ in range(N-1)]

    print(slv(N, u, v, AB))





if __name__ == '__main__':

    main()

# -*- coding: utf-8 -*-

import bisect

import heapq

import math

import random

from collections import Counter, defaultdict, deque

from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal

from fractions import Fraction

from functools import lru_cache, reduce

from itertools import combinations, combinations_with_replacement, product, permutations, accumulate

from operator import add, mul, sub, itemgetter, attrgetter





import sys

# sys.setrecursionlimit(10**6)

# readline = sys.stdin.buffer.readline

readline = sys.stdin.readline



INF = 2**62-1





def read_int():

    return int(readline())





def read_int_n():

    return list(map(int, readline().split()))





def read_float():

    return float(readline())





def read_float_n():

    return list(map(float, readline().split()))





def read_str():

    return readline().strip()





def read_str_n():

    return readline().strip().split()





def ep(*args):

    print(*args, file=sys.stderr)





def mt(f):

    import time



    def wrap(*args, **kwargs):

        s = time.perf_counter()

        ret = f(*args, **kwargs)

        e = time.perf_counter()



        ep(e - s, 'sec')

        return ret



    return wrap





@mt

def slv(N, U, V, AB):

    g = defaultdict(list)

    for a, b in AB:

        g[a].append(b)

        g[b].append(a)



    s = [U]

    prev = {}

    prev[U] = -1

    while s:

        u = s.pop()

        for v in g[u]:

            if v in prev:

                continue

            prev[v] = u

            s.append(v)



    p = [V]

    v = V

    while v != U:

        v = prev[v]

        p.append(v)

    p.reverse()

    nu = p[len(p)//2-1]

    ans = len(p)//2-1

    if len(p) % 2 == 1:

        ans += 1



    done = set(p[len(p)//2-1:])



    d = {nu: 0}

    s = [nu]

    while s:

        u = s.pop()

        for v in g[u]:

            if v in done:

                continue

            d[v] = d[u] + 1

            done.add(u)

            s.append(v)



    return ans + max(d.values())











def main():

    N, U, V = read_int_n()

    AB = [read_int_n() for _ in range(N-1)]

    print(slv(N, U, V, AB))





if __name__ == '__main__':

    main()

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62 - 1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()
        error_print(e - s, "sec")
        return ret

    return wrap


@mt
def slv(N, u, v, AB):
    ans = 0
    g = defaultdict(set)
    for a, b in AB:
        g[a].add(b)
        g[b].add(a)

    def f(start):
        s = [(start, 0)]
        d = {}
        d[start] = 0
        while s:
            c, l = s.pop()
            for n in g[c]:
                if n not in d:
                    s.append((n, l + 1))
                    d[n] = l + 1
        return d

    vd = f(v)
    t = u
    a = v
    s = [(t, 0)]
    d = {}
    d[t] = 0
    while s:
        u, l = s.pop()
        for v in g[u]:
            if v not in d and l + 1 < vd[v]:
                s.append((v, l + 1))
                tmp = vd[v] - (l + 1)
                tmp = (tmp // 2) * 2
                d[v] = tmp + (l + 1)
    d[t] = (vd[t] // 2) * 2
    dest = (0, -1)
    for k, v in d.items():
        dest = max(dest, (v, k))
    ans = dest[0]
    # error_print(dest)
    # error_print(d)
    # error_print(vd)
    if vd[dest[1]] == dest[0]:
        ans -= 1
    return ans


def main():
    N, u, v = read_int_n()
    AB = [read_int_n() for _ in range(N - 1)]
    print(slv(N, u, v, AB))


if __name__ == "__main__":
    main()

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import (
    combinations,
    combinations_with_replacement,
    product,
    permutations,
    accumulate,
)
from operator import add, mul, sub, itemgetter, attrgetter
import sys

# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2**62 - 1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()
        ep(e - s, "sec")
        return ret

    return wrap


@mt
def slv(N, U, V, AB):
    g = defaultdict(list)
    for a, b in AB:
        g[a].append(b)
        g[b].append(a)
    s = [U]
    prev = {}
    prev[U] = -1
    while s:
        u = s.pop()
        for v in g[u]:
            if v in prev:
                continue
            prev[v] = u
            s.append(v)
    p = [V]
    v = V
    while v != U:
        v = prev[v]
        p.append(v)
    p.reverse()
    nu = p[len(p) // 2 - 1]
    ans = len(p) // 2 - 1
    if len(p) % 2 == 1:
        ans += 1
    done = set(p[len(p) // 2 - 1 :])
    d = {nu: 0}
    s = [nu]
    while s:
        u = s.pop()
        for v in g[u]:
            if v in done:
                continue
            d[v] = d[u] + 1
            done.add(u)
            s.append(v)
    return ans + max(d.values())


def main():
    N, U, V = read_int_n()
    AB = [read_int_n() for _ in range(N - 1)]
    print(slv(N, U, V, AB))


if __name__ == "__main__":
    main()

-import sys +from fractions import Fraction -from itertools import combinations, combinations_with_replacement, product, permutations -from operator import add, mul, sub +from itertools import ( +    combinations, +    combinations_with_replacement, +    product, +    permutations, +    accumulate, +) +from operator import add, mul, sub, itemgetter, attrgetter +import sys -sys.setrecursionlimit(100000) -input = sys.stdin.readline +# sys.setrecursionlimit(10**6) +# readline = sys.stdin.buffer.readline +readline = sys.stdin.readline -    return int(input()) +    return int(readline()) -    return list(map(int, input().split())) +    return list(map(int, readline().split())) -    return float(input()) +    return float(readline()) -    return list(map(float, input().split())) +    return list(map(float, readline().split())) -    return input().strip() +    return readline().strip() -    return list(map(str, input().split())) +    return readline().strip().split() -def error_print(*args): +def ep(*args): -        s = time.time() +        s = time.perf_counter() -        e = time.time() -        error_print(e - s, "sec") +        e = time.perf_counter() +        ep(e - s, "sec") -def slv(N, u, v, AB): -    ans = 0 -    g = defaultdict(set) +def slv(N, U, V, AB): +    g = defaultdict(list) -        g[a].add(b) -        g[b].add(a) - -    def f(start): -        s = [(start, 0)] -        d = {} -        d[start] = 0 -        while s: -            c, l = s.pop() -            for n in g[c]: -                if n not in d: -                    s.append((n, l + 1)) -                    d[n] = l + 1 -        return d - -    vd = f(v) -    t = u -    a = v -    s = [(t, 0)] -    d = {} -    d[t] = 0 +        g[a].append(b) +        g[b].append(a) +    s = [U] +    prev = {} +    prev[U] = -1 -        u, l = s.pop() +        u = s.pop() -            if v not in d and l + 1 < vd[v]: -                s.append((v, l + 1)) -                tmp = vd[v] - (l + 1) -                tmp = (tmp // 2) * 2 -                d[v] = tmp + (l + 1) -    d[t] = (vd[t] // 2) * 2 -    dest = (0, -1) -    for k, v in d.items(): -        dest = max(dest, (v, k)) -    ans = dest[0] -    # error_print(dest) -    # error_print(d) -    # error_print(vd) -    if vd[dest[1]] == dest[0]: -        ans -= 1 -    return ans +            if v in prev: +                continue +            prev[v] = u +            s.append(v) +    p = [V] +    v = V +    while v != U: +        v = prev[v] +        p.append(v) +    p.reverse() +    nu = p[len(p) // 2 - 1] +    ans = len(p) // 2 - 1 +    if len(p) % 2 == 1: +        ans += 1 +    done = set(p[len(p) // 2 - 1 :]) +    d = {nu: 0} +    s = [nu] +    while s: +        u = s.pop() +        for v in g[u]: +            if v in done: +                continue +            d[v] = d[u] + 1 +            done.add(u) +            s.append(v) +    return ans + max(d.values()) -    N, u, v = read_int_n() +    N, U, V = read_int_n() -    print(slv(N, u, v, AB)) +    print(slv(N, U, V, AB))