from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a=inp()
        a-=1
        g[i].append(a)
        g[a].append(i)
    return n,g


def dijkstra_back(s,t,n,w,cost):
    #sからtへの最短経路の経路復元
    prev = [s] * n #最短経路の直前の頂点
    d = [10**6] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
        
        for i in range(n):
            if d[i] > d[v] + cost[v][i]: 
                d[i] = d[v] + cost[v][i]
                prev[i] = v
        
    path = [t]
    while prev[t] != s:
        path.append(prev[t])
        prev[t] = prev[prev[t]]
    path.append(s)
    path = path[::-1]
    return path

def dijkstra(s,n,g): # 単一始点最短路問題　sからの最短距離 頂点数n
    s -= 1
    que = []
    d = [10**10 for _ in range(n)]
    d[s] = 0
    heappush( que,(0,s) )
    while len(que)>0:
        p =  heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for i in range(len(g[v])):
            edge = g[v][i]
            if d[edge[0]] > d[v] + edge[1]:
                d[edge[0]] = d[v] + edge[1]
                heappush( que,(d[edge[0]] , edge[0]) )
    return d

def main():
    n,u,v = inpm()
    g = [[] for _ in range(n)]
    cost = [[10**10 for i in range(n)] for i in range(n)] 
    ab = []
    for _ in range(n-1):
        a,b = inpm()
        a -= 1
        b -= 1
        ab.append((a,b))
        g[b].append((a,1))
        g[a].append((b,1))
        cost[a][b]=1
        cost[b][a]=1
    path = dijkstra_back(u-1,v-1,n,n-1,cost)
    dis = len(path)
    ans = int(dis//2)-1
    g = [[] for _ in range(n)]
    for i in range(n-1):
        if ab[i] == (path[ans],path[ans+1]) or ab[i] == (path[ans+1],path[ans]):
            continue
        g[ab[i][0]].append((ab[i][1],1))
        g[ab[i][1]].append((ab[i][0],1))
    d = dijkstra(path[ans]+1,n,g)
    maxd = 0
    for i in range(n):
        if d[i]==10**10:
            continue
        else:
            if maxd<d[i]:
                maxd=d[i]
    x = ans+maxd
    if x==0 and dis==3:
        x+=1
    print(x)


if __name__ == "__main__":
    main()