#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void printVector(vector<auto> v)
{
    int n = v.size();
    rep(i, n)
    {
        cout << v[i] << " ";
    }
    cout << endl;
}

int N;
vector<vector<int>> edge;

vector<int> CalculateCost(int s)
{
    int INF = INT32_MAX;
    vector<int> cost(N, INF);

    cost[s] = 0;
    queue<int> pos_queue;
    pos_queue.push(s);

    while (pos_queue.size())
    {
        int pos = pos_queue.front();
        pos_queue.pop();
        rep(i, edge[pos].size())
        {
            int next = edge[pos][i];
            if (cost[next] == INF)
            {
                cost[next] = cost[pos] + 1;
                pos_queue.push(next);
            }
        }
    }
    return cost;
}

int main()
{
    int u, v;
    cin >> N >> u >> v;
    u--;
    v--;
    edge.resize(N);
    rep(i, N - 1)
    {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        edge[A].push_back(B);
        edge[B].push_back(A);
    }
    vector<int> costT = CalculateCost(u);
    vector<int> costA = CalculateCost(v);
    vector<int> cost(N);
    int escapePoint = 0;
    rep(i, N)
    {
        cost[i] = costA[i] - costT[i];
        if (cost[i] >= 0 && costA[escapePoint] < costA[i])
            escapePoint = i;
    }
    printVector(costA);
    cout << escapePoint << endl;
    long long ans = costA[escapePoint] - 1;
    cout << ans << endl;

    return 0;
}