package main

import "fmt"

func main() {
	var n, u, v int
	fmt.Scan(&n, &u, &v)
	g := make([][]int, n+1)
	var a, b int
	for i := 0; i < n-1; i++ {
		fmt.Scan(&a, &b)
		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
}
