#include <bits/stdc++.h>
using namespace std;
const int Nmax = 1e5 + 5;
vector<int> v[Nmax], a;
int w[Nmax], level[Nmax], ans[Nmax];
int C, n;
long long sum = 0;
void dfs0(int node, int dad = 0) {
  w[node] = 1;
  for (auto it : v[node])
    if (it != dad) {
      dfs0(it, node);
      w[node] += w[it];
    }
}
int find_centroid(int node, int dad = 0) {
  int mx = n - w[node];
  for (auto it : v[node])
    if (it != dad) {
      int res = find_centroid(it, node);
      if (res != -1) return res;
      mx = max(mx, w[it]);
    }
  if (mx <= n / 2) return node;
  return -1;
}
void dfs(int node, int dad = 0, int lev = 0) {
  a.push_back(node);
  sum += lev;
  for (auto it : v[node])
    if (it != dad) dfs(it, node, lev + 1);
}
void print() {
  int i;
  for (i = 0; i < n; ++i) ans[a[i]] = a[(i + n / 2) % n];
  cout << 2 * sum << '\n';
  for (i = 1; i <= n; ++i) cout << ans[i] << ' ';
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int i;
  for (i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs0(1);
  C = find_centroid(1);
  dfs(C);
  print();
  return 0;
}
