import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,u,v = map(int,ipt().split())
    way = [[] for _ in range(n+1)]
    for _ in range(n-1):
        a,b = map(int,ipt().split())
        way[a].append(b)
        way[b].append(a)

    ta = [-1]*(n+1)
    tt = [-1]*(n+1)
    ta[v] = 0 #AOKI
    qa = queue.Queue()
    qt = queue.Queue()
    qt.put((0,u))
    qa.put((0,v))
    while (not qt.empty()) or (not qa.empty()):
        nqt = queue.Queue()
        nqa = queue.Queue()
        while not qt.empty():
            ti,pi = qt.get()
            if ta[pi] != -1:
                continue
            for i in way[pi]:
                if ta[i] == -1:
                    tt[i] = ti+1
                    nqt.put((ti+1,i))
        while not qa.empty():
            ti,pi = qa.get()
            for i in way[pi]:
                if ta[i] == -1:
                    ta[i] = ti+1
                    nqa.put((ti+1,i))
        qt = nqt
        qa = nqa
    ma = 0
    for i,tti in enumerate(tt[1::]):
        tai = ta[i+1]
        if tti == -1:
            continue
        if ma < tti+(tai-tti)//2:
            ma = tti+(tai-tti)//2
    print(ma)


    return

if __name__ == '__main__':
    main()
