using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;


public class Prog
{
    public static void Solve()
    {
        long N = NextLong();
        int u = NextInt() - 1;
        int v = NextInt() - 1;
        List<int>[] next = new List<int>[N];
        for (int i = 0; i < N; i++) next[i] = new List<int>();
        for (int i = 0; i < N - 1; i++)
        {
            int A = NextInt() - 1;
            int B = NextInt() - 1;
            next[A].Add(B);
            next[B].Add(A);
        }
        int[] ao = new int[N];
        Queue<int> Q;
        foreach (var nx in next[v])
        {
            for (int i = 0; i < N; i++) ao[i] = -1;
            Q = new Queue<int>();
            Q.Enqueue(nx);
            ao[nx] = 0;
            bool ok = false;
            while (Q.Count() > 0)
            {
                int now = Q.Dequeue();
                foreach (var e in next[now])
                {
                    if (ao[e] != -1) continue;
                    ao[e] = ao[now] + 1;
                    Q.Enqueue(e);
                    if (e == v) ok = true;
                }
            }
        }
        //青木→高橋方向で探す
        //そっち側しか逃げられん
        int[] tak = new int[N];
        for (int i = 0; i < N; i++) tak[i] = -1;
        Q = new Queue<int>();
        Q.Enqueue(u);
        tak[u] = 0;
        while (Q.Count() > 0)
        {
            int now = Q.Dequeue();
            foreach (var e in next[now])
            {
                if (tak[e] != -1) continue;
                tak[e] = tak[now] + 1;
                Q.Enqueue(e);
            }
        }
        long ans = 1;
        for (int i = 0; i < N; i++)
        {
            if (ao[i] == -1) continue;
            if (ao[i] % 2 == tak[i] % 2)
            {
                ans = Math.Max(ans, ao[i]);
            }
        }
        if (next[u].Count(x => x == v) >= 1) Console.WriteLine(0);
        else Console.WriteLine(ans);

    }
    public static void Main()
    {
        Solve();
        return;
    }
}


public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}
