using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nuv = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nuv[0];
        int u = nuv[1];
        int v = nuv[2];
        var adjList = new List<int>[n + 1];
        for (int i = 1; i < adjList.Length; ++i)
        {
            adjList[i] = new List<int>();
        }
        for (int i = 1; i < n; ++i)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var a = ab[0];
            var b = ab[1];
            adjList[a].Add(b);
            adjList[b].Add(a);
        }

        var mostDepth = 0;
        var driver = new DfsDriver<int>(adjList, v);
        int boundIndex = int.MaxValue;
        int boundVertex = -1;
        while (driver.Depth > 0)
        {
            if (driver.Depth > 2 && driver.VertexAt(-1) == driver.VertexAt(-3))
            {
                driver.Return((x, _) => x);
            }

            if (driver.EndOfSibling)
            {
                mostDepth = boundIndex < driver.Depth && driver.VertexAt(boundIndex) != boundVertex 
                    ? driver.Return((x, _) => x)
                    : driver.Return((x, y) => Math.Max(x, y + 1));
                continue;
            }

            driver.Advance();
            if (driver.VertexAt(-1) == u)
            {
                boundIndex = driver.Depth / 2;
                boundVertex = driver.VertexAt(boundIndex);
            }
        }

        Console.WriteLine(mostDepth - 1);
    }
}

class DfsDriver<T>
{
    struct State
    {
        private int siblingIndex;
        public readonly int Vertex;
        public T Value { get; private set; }
        public State(int v) : this()
        {
            this.Vertex = v;
        }

        public bool AtEnd(List<int>[] adjList) => siblingIndex >= adjList[Vertex].Count;
        public State Branch(List<int>[] adjList) => new State(adjList[Vertex][siblingIndex++]);

        public State Accumulate(Func<T, T, T> func, State child)
        {
            this.Value = func(this.Value, child.Value);
            return this;
        }
    }

    private readonly List<int>[] adjList;
    private readonly StackingList<State> state = new StackingList<State>();
    public int VertexAt(int index) => (index < 0 ? state[state.Count + index] : state[index]).Vertex;
    public int Depth => state.Count;

    public DfsDriver(List<int>[] adjList, int root)
    {
        this.adjList = adjList;
        this.state.Push(new State(root));
    }

    public bool EndOfSibling => state.Peek().AtEnd(adjList);
    public void Advance()
    {
        var s = state.Pop();
        var t = s.Branch(this.adjList);
        state.Push(s);
        state.Push(t);
    }

    public T Return(Func<T, T, T> func)
    {
        var t = this.state.Pop();
        return (this.Depth > 0 ? state[state.Count - 1] = state[state.Count - 1].Accumulate(func, t) : t).Value;
    }

    public override string ToString() => string.Join(" ", state.Select(x => x.Vertex));
}

class StackingList<T> : IEnumerable<T>
{
    readonly List<T> collection = new List<T>();
    public int Count { get; private set; } = 0;
    public T this[int i]
    {
        get
        {
            return collection[i];
        }
        set
        {
            collection[i] = value;
        }
    }

    public void Clear()
    {
        this.Count = 0;
        this.collection.Clear();
        this.collection.TrimExcess();
    }

    public void Push(T item)
    {
        if (this.Count < this.collection.Count)
        {
            this.collection[this.Count] = item;
        }
        else
        {
            this.collection.Add(item);
        }
        ++this.Count;
    }

    public T Peek() => Peek(0);
    public T Peek(int depth) => collection[Count - depth - 1];

    public T Pop()
    {
        var t = this.Peek();
        --this.Count;
        return t;
    }

    public IEnumerator<T> GetEnumerator() => collection.Take(Count).Reverse().GetEnumerator();
    IEnumerator IEnumerable.GetEnumerator() => (IEnumerator)this.GetEnumerator();
}
