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)

    t = 0
    ta = [-1]*(n+1)
    tt = [-1]*(n+1)
    ta[v] = 0 #AOKI
    hqt = [(0,u)]
    hqa = [(0,v)]
    mt = 0
    while hqt or hqa:
        while hqt and hqt[0][0] == t:
            ti,pi = hpq.heappop(hqt)
            if ta[pi] != -1:
                continue
            for i in way[pi]:
                if ta[i] == -1:
                    tt[i] = ti+1
                    hpq.heappush(hqt,(ti+1,i))
        while hqa and hqa[0][0] == t:
            ti,pi = hpq.heappop(hqa)
            for i in way[pi]:
                if ta[i] == -1:
                    ta[i] = ti+1
                    hpq.heappush(hqa,(ti+1,i))
        t += 1
    ma = 0
    for i in range(1,n+1):
        if tt[i] == -1:
            continue
        if ma < tt[i]+(ta[i]-tt[i])//2:
            ma = tt[i]+(ta[i]-tt[i])//2
    print(ma)


    return

if __name__ == '__main__':
    main()
