import java.util.*

fun main(args: Array<String>) {
    val (N, u, v) = readLine()!!.split(" ").map{it.toInt()}
    val A = Array(N - 1) {0}
    val B = Array(N - 1) {0}

    val g = Graph(N, 0, 1e8.toInt()) {a,b -> a + b}

    for (i in A.indices) {
        val (a, b) = readLine()!!.split(" ").map{it.toInt()}
        A[i] = a
        B[i] = b
        g.edges[a - 1].add(Edge(a - 1, b - 1, 1))
        g.edges[b - 1].add(Edge(b - 1, a - 1, 1))
    }

    val da = dijkstra(g, v - 1).first
    val dc = dijkstra(g, u - 1).first

    var res = 0
    for (i in g.edges.indices) {
        if (da[i] <= dc[i]) {
            continue
        }
        if (g.edges[i].size > 1) {
            continue
        }

        res = Math.max(res, da[i] - 1)
    }

    println(res)
}

data class Edge<T: Comparable<T>>(val from: Int, val to: Int, val weight: T): Comparable<Edge<T>> {
    constructor(from: Long, to: Long, weight: T) : this(from.toInt(), to.toInt(), weight)

    override fun compareTo(other: Edge<T>) = weight.compareTo(other.weight)
}

class Graph<T: Comparable<T>>(val n: Int, val zero: T, val inf: T, val plus: (T, T) -> T) {
    val edges = Array(n) { ArrayList<Edge<T>>() }
}

private inline fun <reified T: Comparable<T>>dijkstra(g: Graph<T>, s: Int): Pair<Array<T>, Array<Int>> {
    val N = g.n
    val dist = Array(N) { g.inf }
    val prev = Array(N) {-1}

    val Q = PriorityQueue<Edge<T>>()

    dist[s] = g.zero
    Q.add(Edge(-2, s, g.zero))

    while(Q.isNotEmpty()) {
        val e = Q.peek()
        val v = e.to
        Q.poll()

        if (prev[v] != -1) continue
        prev[v] = e.from
        for (i in g.edges[v]) {
            val d = g.plus(dist[v], i.weight)
            if (dist[i.to] > d) {
                dist[i.to] = d
                Q.add(Edge(i.from, i.to, d))
            }
        }
    }

    return Pair(dist, prev)
}
