package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	u := nextInt()
	v := nextInt()

	g := make([][]int, n+1)
	for i := 0; i < n-1; i++ {
		a := nextInt()
		b := nextInt()
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	vs := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		vs[i] = -1
	}

	vs[v] = 0
	q := make([]int, 0)
	q = append(q, v)
	for len(q) > 0 {
		cv := q[0]
		q = q[1:]
		for _, nv := range g[cv] {
			if vs[nv] > -1 {
				continue
			}
			q = append(q, nv)
			vs[nv] = vs[cv] + 1
		}
	}

	us := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		us[i] = -1
	}
	us[u] = 0
	q = make([]int, 0)
	q = append(q, u)

	ans := 0
	for len(q) > 0 {
		cu := q[0]
		q = q[1:]
		for _, nu := range g[cu] {
			if us[nu] > us[cu] {
				continue
			}
			us[nu] = us[cu] + 1
			if vs[nu] <= us[nu] {
				ans = max(ans, vs[nu])
				continue
			}

			ans = max(ans, us[nu])
			q = append(q, nu)
		}
	}

	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
