#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> gph;
vector<long long> U, V;
void dfsU(long long u, long long t) {
  U[u] = t;
  t++;
  for (auto i : gph[u]) {
    if (U[i] != -1) continue;
    dfsU(i, t);
  }
}
void dfsV(long long v, long long t) {
  V[v] = t;
  t++;
  for (auto i : gph[v]) {
    if (V[i] != -1) continue;
    dfsV(i, t);
  }
}
int32_t main() {
  long long n, u, v, x, y;
  cin >> n >> u >> v;
  u--;
  v--;
  gph.resize(n);
  U.resize(n, -1);
  V.resize(n, -1);
  for (long long i = 0; i < n - 1; i++) {
    cin >> x >> y;
    x--;
    y--;
    gph[x].push_back(y);
    gph[y].push_back(x);
  }
  dfsU(u, 0);
  dfsV(v, 0);
  long long ans = 0;
  for (auto i : U) cout << U[i] << " ";
  cout << endl;
  for (auto i : V) cout << V[i] << " ";
  cout << endl;
  for (long long i = 0; i < n; i++) {
    if (ans < V[i] && U[i] < V[i]) ans = V[i];
  }
  cout << ans - 1;
  return 0;
}
