#include <bits/stdc++.h>
using namespace std;
const int MN = 1e6 + 5;
struct Edge {
  int to, nxt;
} E[MN << 1];
int N, tot, root;
int siz[MN], weight[MN], ans[MN], head[MN];
vector<int> seq;
template <typename T>
inline void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
inline void AddEdge(int u, int v) {
  E[++tot] = (Edge){v, head[u]};
  head[u] = tot;
}
inline void centroid(int u, int fa) {
  siz[u] = 1;
  weight[u] = 0;
  for (int i = head[u]; i; i = E[i].nxt) {
    int v = E[i].to;
    if (v == fa) continue;
    centroid(v, u);
    siz[u] += siz[v];
    weight[u] = max(weight[u], siz[v]);
  }
  chkmax(weight[u], N - siz[u]);
  if (weight[u] < weight[root]) root = u;
}
inline void dfs_seq(int u, int fa) {
  seq.emplace_back(u);
  for (int i = head[u]; i; i = E[i].nxt)
    if (E[i].to != fa) dfs_seq(E[i].to, u);
}
int main() {
  read(N);
  for (int i = 1; i < N; ++i) {
    int u, v;
    read(u), read(v);
    AddEdge(u, v);
    AddEdge(v, u);
  }
  weight[root = 0] = N;
  centroid(1, 0);
  dfs_seq(root, 0);
  for (int i = 0; i < N; ++i) ans[seq[i]] = seq[(i + N / 2) % N];
  long long res = 0;
  for (int i = 1; i <= N; ++i) res += (long long)min(siz[i], N - siz[i]);
  printf("%lld\n", 2LL * res);
  for (int i = 1; i <= N; ++i) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
