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

static class Program
{
    class Node
    {
        public int Depth { get; private set; }
        public Node Parent { get; set; }
        public List<Node> Children { get; private set; }
        
        public Node()
        {
            Children = new List<Node>();
        }

        public void SetDepth(int n)
        {
            Depth = n;
            foreach (var child in Children)
            {
                child.SetDepth(n + 1);
            }
        }

        public int Deepest(int n)
        {
            return (Children.Count > 0) ? Children.Max(child => child.Deepest(n + 1)) : n;
        }

        public void Cut(int n, Node child)
        {
            if (n <= 0) { Children = new List<Node> { child }; }
            if (Parent != null) { Parent.Cut(n - 1, this); }
        }
    }

    static int Solve(Node u, Node v)
    {
        v.SetDepth(0);
        int d = u.Depth;
        u.Cut((d + 1) / 2, null);
        int n = v.Deepest(0);
        return n - 1;
    }

    static void Main(string[] args)
    {
        var V1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int N = V1[0], u = V1[1] - 1, v = V1[2] - 1;
        var nodes = new Node[N];
        var edges = new List<int>[N];
        for (int i = 0; i < N; ++i)
        {
            nodes[i] = new Node();
            edges[i] = new List<int>();
        }
        for (int i = 0; i < N - 1; ++i)
        {
            var V2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int a = V2[0] - 1, b = V2[1] - 1;
            edges[a].Add(b);
            edges[b].Add(a);
        }
        var visited = new bool[N];
        var queue = new Queue<int>();
        visited[v] = true;
        queue.Enqueue(v);
        while (queue.Count > 0)
        {
            int a = queue.Dequeue();
            foreach (int b in edges[a])
            {
                if (!visited[b])
                {
                    nodes[b].Parent = nodes[a];
                    nodes[a].Children.Add(nodes[b]);
                    visited[b] = true;
                    queue.Enqueue(b);
                }
            }
        }
        Console.WriteLine(Solve(nodes[u], nodes[v]));
    }
}
