fun main(args: Array<String>) {

    var (N, t, a) = readLine()!!.split(" ").map(String::toInt)
    t -= 1
    a -= 1

    val graph = Array(N) {
        mutableListOf<Int>()
    }

    repeat(N - 1) {
        val (v1, v2) = readLine()!!.split(" ").map(String::toInt).map { it - 1 }
        graph[v1].add(v2)
        graph[v2].add(v1)
    }

    fun calcDistance(v: Int): IntArray {
        val distance = IntArray(N)
        fun dfs(v: Int, d: Int, parentV: Int) {
            distance[v] = d
            for (adjacencyV in graph[v]) {
                if (adjacencyV == parentV) {
                    continue
                }
                dfs(adjacencyV, d + 1, v)
            }
        }
        dfs(v, 0, -1)
        return distance
    }


    val distanceT = calcDistance(t)
    val distanceA = calcDistance(a)

    var ans = 0
    for (i in 0 until N) {
        if (distanceT[i] < distanceA[i]) {
            ans = Math.max(ans, distanceA[i])
        }
    }

    println(ans - 1)
}