from heapq import heappush, heappop
def main():
    def dijkstra_search(s):
        d = [INF] * n
        searched = [False] * n
        d[s] = 0
        searched[s] = True
        edge_list = []
        count = 1
        for i in edge[s]:
            heappush(edge_list,i)
        while edge_list:
            min_d,min_v = heappop(edge_list)
            if searched[min_v] or min_d > d[min_v]:
                continue
            v = min_v
            d[v] = min_d
            searched[v] = True
            count += 1
            for i,j in edge[v]:
                next_d = i+d[v]
                if not searched[j]:
                    heappush(edge_list,(next_d,j))
            if count == n:
                break
        return d
    
    def dijkstra_back(s,t):
        prev = [s] * n
        d = [float("inf")] * 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
    
    n,tk,ao = map(int,input().split())
    tk = tk-1
    ao = ao-1
    route = [tuple(map(int,input().split())) for _ in range(n-1)]
    INF = float('inf')
    edge = [[] for _ in range(n)]
    for i in route:
        edge[i[0]-1].append((1,i[1]-1))
        edge[i[1]-1].append((1,i[0]-1))
    cost = [[INF for i in range(n)] for i in range(n)] 
    for i in route:
        cost[i[0]-1][i[1]-1] = 1
        cost[i[1]-1][i[0]-1] = 1
    dtk = dijkstra_search(tk)
    dao = dijkstra_search(ao)
    sdao = sorted([(j,i) for i,j in enumerate(dao)],reverse=True)
    ans = INF
    for i in sdao:
        g = i[0]
        rtk = dijkstra_back(tk,g)
        f = False
        for j in rtk:
            if dtk[j] >= dao[j] and dtk[j]%2 == dao[j]%2:
                pass
            else:
                ans = max([dao[j],dtk[j]+1])
                if dao[j]%2 == (dtk[j]+1)%2:
                    ans -= 1
                f = True
                break
        if f:
            print(ans)
            break
    
if __name__ == '__main__':
    main()