import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
import std.numeric;
void main()
{
    auto buf = readln.chomp.split.to!(int[]);
    immutable
            n = buf[0],
            takahashi = buf[1] - 1,
            aoki = buf[2] - 1;
    auto tree = Tree(new Tree.Node[n]);
    foreach (i; 0..n)
        tree.nodes[i].label = i;
    foreach (i; 1..n)
    {
        buf = readln.chomp.split.to!(int[]);
        tree.nodes[buf[0]-1].neighbor ~= buf[1] - 1;
        tree.nodes[buf[1]-1].neighbor ~= buf[0] - 1;
    }
    void dfs(int i)
    {
        foreach (n; tree.nodes[i].neighbor)
        {
            if (tree.nodes[i].parent == n)
                continue;
            stderr.writefln("%d < %d", i, n);
            tree.nodes[n].parent = i;
            tree.nodes[i].children ~= n;
            dfs(n);
        }
    }
    tree.nodes[aoki].parent = aoki;
    dfs(aoki);

    int ret;
    int t = takahashi;
    while (t != aoki)
    {
        stderr.writefln("t = %d", t);
        auto room = tree.deepest(t);
        auto distance = tree.depth(t);
        ret = ret.max(moves(distance, room));
        t = tree.nodes[t].parent;
        if (t == aoki) break;
        t = tree.nodes[t].parent;
    }
    ret.writeln;
}
struct Tree
{
    Node[] nodes;
    int[int] m_deepest, m_depth;
    struct Node
    {
        int label;
        int[] neighbor;
        int[] children;
        int parent;
    }
    int deepest(int label)
    {
        if (auto p = label in m_deepest)
            return *p;
        if (nodes[label].children.empty)
            return m_deepest[label] = 0;
        return m_deepest[label] = nodes[label].children.map!(_=>deepest(_)).reduce!max+1;
    }
    int depth(int label)
    {
        if (auto p = label in m_depth)
            return *p;
        if (nodes[label].parent == label)
            return m_depth[label] = 0;
        return m_depth[label] = depth(nodes[label].parent) + 1;
    }
}
int moves(int distance, int room)
{
    stderr.writefln("moves(%d, %d)", distance, room);
    if (distance == 0)
        return 0;
    return (distance - 1) + room;
}
