#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(const T x, const T y) {
  if (!y) {
    return x;
  }
  return gcd(y, x % y);
}
template <class T>
T lcm(const T x, const T y) {
  return x / gcd(x, y) * y;
};
template <class T>
T modpow(const T x, const T n, const T mod) {
  T res = 1;
  while (n > 0) {
    if (n % 2) res = res * x % mod;
    x = x * x % mod;
    n /= 2;
  };
  return res;
}
template <class T>
bool alltrue(const T &a) {
  return all_of((a).begin(), (a).end(), [](bool x) { return x; });
}
template <class T>
bool anytrue(const T &a) {
  return any_of((a).begin(), (a).end(), [](bool x) { return x; });
}
template <class T>
bool contain(const T &a, const T &b) {
  for (auto x : b) {
    if (a.find(x) == a.end()) {
      return false;
    }
  }
  return true;
}
template <class T>
bool mmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <class T>
bool mmin(T &m, const T q) {
  if (m > q) {
    m = q;
    return true;
  } else
    return false;
}
template <class T>
int siz(const T &a) {
  return (int)a.size();
}
template <class T>
set<T> devisers(T n) {
  set<T> res;
  for (T i = 1; i < (T)sqrt(n) + 1; i++) {
    if (n % i == 0) {
      res.insert(i);
      res.insert(n / i);
    }
  }
  return res;
}
template <class T>
void concat(T &a, const T &b) {
  a.insert(a.end(), b.begin(), b.end());
}
template <class T>
void getand(const T &a, const T &b, T &c) {
  set_intersection(a.begin(), a.end(), b.begin(), b.end(),
                   inserter(c, c.end()));
}
template <class T>
void getor(const T &a, const T &b, T &c) {
  set_union(a.begin(), a.end(), b.begin(), b.end(), inserter(c, c.end()));
}
const long long MOD = 1e9 + 7;
const int MAX = 1e5 + 100;
vector<long long> dijkstra(int V, int s, vector<vector<long long>> &G) {
  vector<long long> d(V, LLONG_MAX);
  d[s] = 0;
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      q;
  q.push({0, s});
  while (!q.empty()) {
    int precost, v;
    tie(precost, v) = q.top();
    q.pop();
    if (d[v] < precost) continue;
    for (long long n : G[v]) {
      if (d[n] > d[v] + 1) {
        d[n] = d[v] + 1;
        q.push({d[n], n});
      }
    }
  }
  return d;
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<vector<long long>> G(N);
  for (long long i = (long long)(0); i < (long long)(N - 1); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<long long> d1 = dijkstra(N, u, G);
  vector<long long> d2 = dijkstra(N, v, G);
  for (auto x : d1) cout << x << ' ';
  cout << endl;
  for (auto x : d2) cout << x << ' ';
  cout << endl;
  long long ans = 0;
  for (long long i = (long long)(0); i < (long long)(N); ++i) {
    if (d1[i] >= d2[i]) continue;
    mmax(ans, d2[i]);
  }
  cout << ans - 1 << endl;
  return 0;
}
