using System;
using System.Linq;
using CompLib.Util;
using System.Threading;
using System.Collections.Generic;

public class Program
{
    int N;
    int U, V;
    AdjacencyList E;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        U = sc.NextInt() - 1;
        V = sc.NextInt() - 1;
        E = new AdjacencyList(N);

        for (int i = 0; i < N - 1; i++)
        {
            E.AddUnDirectedEdge(sc.NextInt() - 1, sc.NextInt() - 1);
        }

        E.Build();
        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();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

class AdjacencyList
{
    private readonly int _n;
    private readonly List<(int f, int t)> _edges;

    private int[] _start;
    private int[] _eList;

    public AdjacencyList(int n)
    {
        _n = n;
        _edges = new List<(int f, int t)>();
    }

    public void AddDirectedEdge(int from, int to)
    {
        _edges.Add((from, to));
    }

    public void AddUnDirectedEdge(int f, int t)
    {
        AddDirectedEdge(f, t);
        AddDirectedEdge(t, f);
    }

    public void Build()
    {
        _start = new int[_n + 1];
        foreach (var e in _edges)
        {
            _start[e.f + 1]++;
        }
        for (int i = 1; i <= _n; i++)
        {
            _start[i] += _start[i - 1];
        }

        int[] counter = new int[_n + 1];
        _eList = new int[_edges.Count];

        foreach (var e in _edges)
        {
            _eList[_start[e.f] + counter[e.f]++] = e.t;
        }
    }

    public ReadOnlySpan<int> this[int f]
    {
        get { return _eList.AsSpan(_start[f], _start[f + 1] - _start[f]); }
    }
}

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: 47892