#include <bits/stdc++.h>
using namespace std;
const int NN = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 25;
const long long mod = 1e9 + 7;
const int inf = 1e9 + 7;
const double long rf = 1e-14;
const int B = sqrt(N);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
long long res;
int cnt;
int s[N];
int ans[N];
bool used[N];
vector<int> v[N], g;
void dfs(int x, int p) {
  s[x] = 1;
  for (auto y : v[x]) {
    if (y == p) continue;
    dfs(y, x);
    s[x] += s[y];
  }
}
void fnd(int x) {
  used[x] = true;
  for (auto y : v[x]) {
    if (y == x || used[y]) continue;
    if (s[y] * 2 > n) {
      fnd(y);
      return;
    }
  }
  cnt = x;
}
void foo(int x, int p) {
  for (auto y : v[x]) {
    if (y == p) continue;
    foo(y, x);
  }
  g.push_back(x);
}
void solve1() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, 1);
  fnd(1);
  foo(cnt, cnt);
  for (int i = 1; i <= n; i++) {
    res += 2 * 1ll * min(n - s[i], s[i]);
  }
  cout << res << "\n";
  for (int i = 0; i < n; i++) {
    ans[g[i]] = g[(i + n / 2) % n];
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int cghf = 1;
  while (cghf--) {
    solve1();
  }
}
