import java.util.*

fun main(args: Array<String>) {
    var (N,u,v) = readLine()!!.split(" ").map(String::toInt)

    var tree = LinkedHashMap<Int,ArrayList<Int>>()

    for(i in 1 until N){
        var (a,b) = readLine()!!.split(" ").map(String::toInt)

        if(!tree.containsKey(a)){
            tree[a] = ArrayList()
        }
        tree[a]!!.add(b)

        if(!tree.containsKey(b)){
            tree[b] = ArrayList()
        }
        tree[b]!!.add(a)
    }

    var fastMap = GetFastMap(tree,v).getFastMap()

    var pos = u//ポジション
    var max = 0//最大値
    var costs = LinkedHashMap<Int, Int>()//コスト
    var stack = ArrayDeque<Int>()//スタック

    costs[u] = 0

    for(x in 0 until 100000){
        for(branch in tree[pos]!!) {
            if(!stack.contains(branch)){
                costs[branch] = costs[pos]!! + 1
                if(costs[branch]!! > fastMap[branch]!!){
                    max = Math.max(costs[branch]!!-1,max)
                }else if(costs[branch]!! == fastMap[branch]!!){
                    max = Math.max(costs[branch]!!,max)
                }else{
                    stack.offer(branch)
                }
            }
        }
        if(stack.size == 0){
            break
        }
        pos = stack.poll()
    }

    println(max)
}


class GetFastMap(var tree: LinkedHashMap<Int,ArrayList<Int>>,var position : Int){
    fun getFastMap() : LinkedHashMap<Int, Int>{
        var costs = LinkedHashMap<Int, Int>()//コスト
        var stack = ArrayDeque<Int>()//スタック
        var old = ArrayList<Int>()//探索済みList

        costs[position] = 0

        while(true){
            for(branch in tree[position]!!){
                if(!stack.contains(branch)){
                    if(old.contains(branch)){
                        costs[branch] = Math.min(costs[position]!!+1,costs[branch]!!)
                    }else{
                        costs[branch] = costs[position]!!+1
                        stack.offer(branch)
                    }
                }
            }
            old.add(position)

            if(stack.size == 0){
                break
            }

            position = stack.poll()
        }

        return costs
    }
}