#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, inf = 0x3f3f3f3f;
int eid, p[N], n, sz[N], mn = inf, root;
int cnt, ans[N], SZ[N], b[N];
long long res = 0;
struct edge {
  int v, nxt;
} e[N << 1];
inline void addedge(int u, int v) { e[++eid] = (edge){v, p[u]}, p[u] = eid; }
inline void dfs0(int u, int fa) {
  int mx = 0;
  sz[u] = 1;
  for (int i = p[u]; i; i = e[i].nxt)
    if (e[i].v != fa) {
      int v = e[i].v;
      dfs0(v, u), sz[u] += sz[v], mx = max(mx, sz[v]);
    }
  mx = max(mx, fa ? n - sz[u] : 0);
  if (mx < mn) mn = mx, root = u;
}
vector<int> v[N];
inline void dfs1(int u, int fa) {
  sz[u] = 1;
  for (int i = p[u]; i; i = e[i].nxt)
    if (e[i].v != fa) dfs1(e[i].v, u), sz[u] += sz[e[i].v];
}
inline void dfs(int u, int fa) {
  v[cnt].push_back(u), res += 1ll * min(sz[u], n - sz[u]) * 2;
  for (int i = p[u]; i; i = e[i].nxt)
    if (e[i].v != fa) dfs(e[i].v, u);
}
int main() {
  scanf("%d", &n);
  if (n == 2) {
    printf("2\n2 1");
    return 0;
  }
  for (int i = (1); i <= (n - 1); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v), addedge(v, u);
  }
  dfs0(1, 0), dfs1(root, 0), mn = inf;
  for (int i = p[root]; i; i = e[i].nxt) {
    cnt++, dfs(e[i].v, root);
    SZ[cnt] = v[cnt].size(), mn = min(mn, SZ[cnt]);
  }
  for (int i = (1); i <= (cnt); i++)
    if (mn == SZ[i]) {
      v[i].push_back(root), SZ[i]++;
      break;
    }
  printf("%lld\n", res);
  int nn = 0, mx = 0;
  for (int i = (1); i <= (cnt); i++) {
    for (int j = (0); j <= (SZ[i] - 1); j++) b[nn++] = v[i][j];
    mx = max(mx, SZ[i]);
  }
  for (int i = (0); i <= (n - 1); i++) ans[b[i]] = b[(i + mx) % n];
  for (int i = (1); i <= (n); i++) printf("%d ", ans[i]);
  return 0;
}
