import sys
import math
sys.setrecursionlimit(1000000)

class LCA():
    def __init__(self, tree, N):
        self.tree = tree
        self.N = N
        self.dist = [-1]*(self.N)   # distance from root
    
        self.K = 1
        while (1 << self.K) < self.N:
            self.K += 1
        self.parents = [[-1]*(self.N) for i in range(self.K)]    # parents[k][u]: 2^k-th parent of u

        self.dfs(0, 0, -1)

        for k in range(self.K - 1):
            for v in range(self.N):
                if self.parents[k][v] < 0:
                    self.parents[k + 1][v] = -1
                else:
                    self.parents[k + 1][v] = self.parents[k][self.parents[k][v]]

    def dfs(self, v, d, p):
        self.dist[v] = d
        self.parents[0][v] = p
        for child in self.tree[v]:
            if self.dist[child] < 0:
                self.dfs(child, d + 1, v)
    
    def query(self, u, v):
        if self.dist[u] < self.dist[v]:
            u, v = v, u
        
        for k in range(self.K):
            if (self.dist[u] - self.dist[v]) >> k & 1:
                u = self.parents[k][u]
        
        if u == v:
            return u
        for k in range(self.K - 1, -1, -1):
            if self.parents[k][u] != self.parents[k][v]:
                u = self.parents[k][u]
                v = self.parents[k][v]
        
        return self.parents[0][u]
    
    def distBetween(self, u, v):
        return self.dist[u] + self.dist[v] - 2 * self.query(u, v)

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)

lca = LCA(tree, N)

dist_max = 0
v_end = 0
for i in range(N):
    if lca.distBetween(u, i) < lca.distBetween(v, i):
        if dist_max <= lca.distBetween(v, i):
            dist_max = lca.distBetween(v, i)
            v_end = i

print(lca.distBetween(v, v_end) - 1)