#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int n;
vector<vector<int>> con;
vector<int> arr;
long long total = 0;
vector<int> ans;
int idx = -1, l, r;
long long dfs(int x, int p) {
  arr.push_back(x);
  long long k = 1;
  for (int c : con[x]) {
    if (c != p) {
      k += dfs(c, x);
    }
  }
  if (k >= n - k) {
    if (idx == -1) {
      idx = x;
      r = arr.size() - 1;
      l = r - k + 1;
    }
    total += 2 * (n - k);
  } else
    total += 2 * k;
  return k;
}
int main() {
  cin >> n;
  con = vector<vector<int>>(n + 1);
  ans = vector<int>(n + 1);
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    con[a].push_back(b);
    con[b].push_back(a);
  }
  dfs(1, 0);
  int asign = 2 * (r - l + 1) - n;
  int pl = l;
  int pr = r - (asign - 1) / 2;
  for (int i = 0; i < asign; i++) {
    if (i & 1) {
      ans[arr[pr]] = arr[pl];
      pl++;
      pr++;
    } else {
      ans[arr[pl]] = arr[pr];
    }
  }
  if (asign == n) {
    if (n & 1) {
      ans[arr[pr]] = arr[l];
    }
  } else {
    int pos = 0;
    if (pos >= l && pos <= r) pos = r + 1;
    if (asign & 1) {
      ans[arr[pos]] = arr[pl];
      ans[arr[pr]] = arr[pos];
      pl++;
      asign += 2;
      pos++;
    }
    for (int i = 0; i < n - asign; i++) {
      if (pos >= l && pos <= r) pos = r + 1;
      if (i & 1) {
        ans[arr[pos]] = arr[pl];
        pl++;
        pos++;
      } else {
        ans[arr[pl]] = arr[pos];
      }
    }
  }
  cout << total << endl;
  for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
  cout << endl;
  return 0;
}
