using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using CompLib.Util;

public class Program
{
    int N;
    int U, V;
    List<int>[] E;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        U = sc.NextInt() - 1;
        V = sc.NextInt() - 1;
        E = new List<int>[N];
        for (int i = 0; i < N; i++)
        {
            E[i] = new List<int>();
        }

        for (int i = 0; i < N - 1; i++)
        {
            int a = sc.NextInt() - 1;
            int b = sc.NextInt() - 1;
            E[a].Add(b);
            E[b].Add(a);
        }

        // vの根付き木
        // 
        // u できるだけ上がって一番深い頂点に向かう

        // vよりuが早い一番深いとこ
        // 

        var distV = Go(V);
        var distU = Go(U);

        var sorted = new int[N];
        for (int i = 0; i < N; i++)
        {
            sorted[i] = i;
        }

        Array.Sort(sorted, (l, r) => distV[r].CompareTo(distV[l]));

        foreach (var i in sorted)
        {
            if (distU[i] < distV[i])
            {
                Console.WriteLine(distV[i] - 1);
                return;
            }
        }
    }

    int[] Go(int r)
    {
        int[] result = new int[N];
        for (int i = 0; i < N; i++)
        {
            result[i] = int.MaxValue;
        }

        var q = new Queue<int>();
        q.Enqueue(r);
        result[r] = 0;

        while (q.Count > 0)
        {
            var d = q.Dequeue();
            foreach (var to in E[d])
            {
                if (result[to] <= result[d] + 1) continue;
                result[to] = result[d] + 1;
                q.Enqueue(to);
            }
        }
        return result;
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 49360