#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
int mod = 1e9 + 7;



struct len {
    int aoki, takahasi;
};

int N, u, v;
vector<int> up[100005], down[100005];
len ans[100005];

void dfsA(int coordinate, int count = 0) {
    ans[coordinate].aoki = count;
    for (int i : up[coordinate]) {
        dfsA(i, count + 1);
    }
}

void dfsT(int coordinate, int count = 0) {
    ans[coordinate].takahasi = count;
    for (int i : down[coordinate]) {
        dfsT(i, count + 1);
    }
}

int answer = 0;

void dfs_ans(int coordinate) {
    if (up[coordinate].size() == 0) {
        answer = max(answer, ans[coordinate].aoki);
    }
    if (up[coordinate].size() == 1) dfs_ans(up[coordinate][0]);
    if (up[coordinate].size() >= 2) {
        if (ans[coordinate].takahasi < ans[coordinate].aoki) {
            for (int i : up[coordinate]) {
                dfs_ans(i);
            }
        }
    }
}

signed main() {
    cin >> N >> u >> v;
    for (int i = 0; i < N - 1; i++) {
        int A, B;
        cin >> A >> B;
        up[A].push_back(B);
        down[B].push_back(A);
    }
    dfsT(u);
    dfsA(v);
    for (int i = 1; i <= N; i++) {
        cout << ans[i].takahasi << " " << ans[i].aoki << endl;
    }
    answer = ans[u].aoki;
    dfs_ans(1);
    cout << answer << endl;
}