//DFSテンプレート
fun main(args: Array<String>) {
    var (N, U, V) = listOfInt()
    U -= 1; V -= 1
    val G = Array<MutableList<Int>>(N) { mutableListOf<Int>() }
    repeat(N - 1) {
        val (a, b) = listOfInt(-1)
        G[a].add(b)
        G[b].add(a)
    }
    var dist = Array<Int>(N) { 0 }
    tailrec fun dfs(v: Int, d: Int = 0, p: Int = -1) {
        dist[v] = d
        for (u in G[v]) {
            if (u == p) continue
            dfs(u, d + 1, v)
        }
    }
    fun calcDist(s: Int): Array<Int> {
        dist = Array<Int>(N) { 0 }
        dfs(s)
        return dist
    }
    val distU = calcDist(U)
    val distV = calcDist(V)

    var max = 0
    repeat(N) {
        if (distU[it] < distV[it]) {
            max = Math.max(max, distV[it])
        }
    }
    val ans = max - 1
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }