import queue
N, u, v = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N - 1)]

children = [[] for i in range(N + 1)]

for i in range(N - 1):
        children[AB[i][0]].append(AB[i][1])
        children[AB[i][1]].append(AB[i][0])

def aoki(u, v):
        atot = [[-1, 0] for i in range(N + 1)]
        atot[v][0] = 0
        q = queue.Queue()
        for i in children[v]:
                q.put([i, v])
        while not q.empty():
                nt = q.get()
                if nt[0] == u:
                        atot[nt[0]] = [atot[nt[1]][0] + 1, nt[1]]
                        break
                else:
                        for i in children[nt[0]]:
                                if atot[i][0] == -1:
                                        q.put([i, nt[0]])
                        atot[nt[0]] = [atot[nt[1]][0] + 1, nt[1]]
        bk = u
        rout = [bk]
        while atot[bk][0] > 0:
                rout.append(atot[bk][1])
                bk = atot[bk][1]

        return rout

def takahashi(u, v):
        froma = [[-1, 0] for i in range(N + 1)]
        froma[u][0] = 0
        q = queue.Queue()
        for i in children[u]:
                q.put([i, u])
        mx = -1
        while not q.empty():
                nt = q.get()
                for i in children[nt[0]]:
                        if froma[i][0] == -1 and nt[0] != v:
                                q.put([i, nt[0]])
                froma[nt[0]] = [froma[nt[1]][0] + 1, nt[1]]
                if froma[nt[0]][0] > mx:
                        g = nt[0]
                        mx = froma[nt[0]][0]
        rout = aoki(g, u)
        if rout[-2] == v:
                aw = v
                for i in children[u]:
                        if i != v:
                                aw = i
                                return aw
                if aw == v:
                        return v
        else:
                return rout[-2]

cnt = 0
while True:
        u = takahashi(u, v)
        if u == v:
                break
        r = aoki(u, v)
        if len(r) == 1:
                v = r[0]
        else:
                v = r[-2]
        if u == v:
                cnt += 1
                break
        cnt += 1
print(cnt)