import java.util.ArrayDeque
import java.math.*

fun main(args: Array<String>) {
    var (N, u, v) = readInputLine().split(" ").map { it.toInt() }
    u--
    v--
    val edges = Array(N) { mutableListOf<Int>() }

    if (u == v) {
        println(0)
        return
    }

    for (i in 1 until N) {
        val (A, B) = readInputLine().split(" ").map { it.toInt() - 1 }
        edges[A].add(B)
        edges[B].add(A)
    }

    // (node, parent)
    val queue = ArrayDeque<Pair<Int, Int>>()
    val uDist = IntArray(N) { -1 }
    val vDist = IntArray(N)

    for (e in edges[v]) {
        queue.add(Pair(e, v))
    }

    while (queue.isNotEmpty()) {
        val (n, p) = queue.poll()!!
        vDist[n] = vDist[p] + 1

        for (e in edges[n]) {
            if (e == p) {
                continue
            }
            queue.add(Pair(e, n))
        }
    }

    uDist[u] = 0

    for (e in edges[u]) {
        queue.add(Pair(e, u))
    }

    while (queue.isNotEmpty()) {
        val (n, p) = queue.poll()!!
        val tmp = uDist[p] + 1
        if (tmp >= vDist[n]) {
            continue
        }
        uDist[n] = tmp

        for (e in edges[n]) {
            if (e == p) {
                continue
            }
            queue.add(Pair(e, n))
        }
    }

    var leaf = u

    for (i in 0 until N) {
        if (uDist[i] == -1) {
            continue
        }
        if (vDist[i] > vDist[leaf]) {
            leaf = i
        }
    }

    /*
    println(uDist.joinToString(" "))
    println(vDist.joinToString(" "))

    println(leaf)

     */

    println(vDist[leaf] - 1)
}

fun readInputLine(): String {
    return readLine()!!
}
