import sys
import math
sys.setrecursionlimit(1000000)

class DFS():
    def __init__(self, tree, N, root):
        self.tree = tree
        self.N = N
        self.dist = [-1]*(self.N)   # distance from root
    
        self.dfs(root, 0)

    def dfs(self, v, d):
        self.dist[v] = d
        for child in self.tree[v]:
            if self.dist[child] < 0:
                self.dfs(child, d + 1)

N, u, v = list(map(int, input().split()))
tree = [[] for i in range(N)]

u -= 1
v -= 1

for i in range(N - 1):
    a, b = list(map(int, input().split()))
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

dfs_u = DFS(tree, N, u)
dfs_v = DFS(tree, N, v)

d_max = 0
for i in range(N):
    if dfs_u.dist[i] < dfs_v.dist[i]:
        if d_max <= dfs_v.dist[i]:
            d_max = dfs_v.dist[i]

print(d_max - 1)