import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;

            List<Integer>[] edges = new List[N];
            for (int i = 0; i < N; i++) {
                edges[i] = new ArrayList<>();
            }

            for (int i = 0; i < N - 1; i++) {
                int a = sc.nextInt() - 1;
                int b = sc.nextInt() - 1;
                edges[a].add(b);
                edges[b].add(a);
            }

            int[] d = new int[N];
            for (int i = 0; i < N; i++) {
                d[i] = Integer.MAX_VALUE;
            }
            d[u] = 0;
            dfs(u, d, edges);

            int[] e = new int[N];
            for (int i = 0; i < N; i++) {
                e[i] = Integer.MAX_VALUE;
            }
            e[v] = 0;
            dfs(v, e, edges);

            int q = 0;
            for (int i = 0; i < N; i++) {
                if (d[i] < e[i]) {
                    if (e[i] > q) {
                        q = e[i];
                    }
                }
            }

            if (q == 0) {
                System.out.println(0);
            } else {
                System.out.println(q - 1);
            }
        }
    }

    static void dfs(int u, int[] d, List<Integer>[] edges) {
        for (Integer nu : edges[u]) {
            if (d[nu] == Integer.MAX_VALUE) {
                d[nu] = d[u] + 1;
                dfs(nu, d, edges);
            }
        }
    }

}
