#include <bits/stdc++.h>
using namespace std;
struct IO {
  char buf[(1 << 20)], *p1, *p2;
  char pbuf[(1 << 20)], *pp;
  IO() : p1(buf), p2(buf), pp(pbuf) {}
  inline char gc() {
    return getchar();
    if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin);
    return p1 == p2 ? ' ' : *p1++;
  }
  inline bool blank(char ch) {
    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
  }
  template <class T>
  inline void read(T &x) {
    register double tmp = 1;
    register bool sign = 0;
    x = 0;
    register char ch = gc();
    for (; !(ch >= '0' && ch <= '9'); ch = gc())
      if (ch == '-') sign = 1;
    for (; (ch >= '0' && ch <= '9'); ch = gc()) x = x * 10 + (ch - '0');
    if (ch == '.')
      for (ch = gc(); (ch >= '0' && ch <= '9'); ch = gc())
        tmp /= 10.0, x += tmp * (ch - '0');
    if (sign) x = -x;
  }
  inline void read(char *s) {
    register char ch = gc();
    for (; blank(ch); ch = gc())
      ;
    for (; !blank(ch); ch = gc()) *s++ = ch;
    *s = 0;
  }
  inline void read(char &c) {
    for (c = gc(); blank(c); c = gc())
      ;
  }
  template <class t>
  inline void write(t x) {
    if (x < 0)
      putchar('-'), write(-x);
    else {
      if (x > 9) write(x / 10);
      putchar('0' + x % 10);
    }
  }
} io;
const long long mo = 1e9 + 7;
const long long Mo = 998244353;
const long long N = 1e5 + 5;
vector<long long> h[N], g[N];
long long n, m, ans, Rt, gs, id[N], siz[N], Ans[N], zx[N];
struct Node {
  long long id, sz, tim;
  inline bool friend operator<(const Node &s, const Node &t) {
    return s.sz < t.sz;
  }
};
priority_queue<Node> q;
inline void dfs(long long u, long long fa) {
  siz[u] = 1;
  for (long long i : h[u])
    if (i ^ fa) dfs(i, u), siz[u] += siz[i], zx[u] = max(zx[u], siz[i]);
  zx[u] = max(zx[u], n - siz[u]);
  if (zx[Rt] > zx[u]) Rt = u;
  ans += 2ll * min(siz[u], n - siz[u]);
}
inline void dfs1(long long u, long long fa) {
  g[id[u] = gs].emplace_back(u);
  for (long long i : h[u])
    if (i ^ fa) dfs1(i, u);
}
namespace Big {
inline void solve() {
  zx[0] = n + 1;
  dfs(1, 0);
  for (long long i : h[Rt]) gs++, dfs1(i, Rt);
  for (long long i = (1); i <= (gs); i++)
    q.push((Node){i, (long long)g[i].size(), 0});
  if (n & 1) {
    long long sz = (n - 3) >> 1ll;
    for (; sz--;) {
      Node mx = q.top();
      q.pop();
      Node cx = q.top();
      q.pop();
      Ans[g[mx.id][mx.tim]] = g[cx.id][cx.tim];
      Ans[g[cx.id][cx.tim]] = g[mx.id][mx.tim];
      mx.tim++, cx.tim++, mx.sz--, cx.sz--;
      if (mx.sz) q.push(mx);
      if (cx.sz) q.push(cx);
    }
    Node mx = q.top();
    q.pop();
    Node cx = q.top();
    q.pop();
    Ans[Rt] = g[mx.id][mx.tim];
    Ans[g[mx.id][mx.tim]] = g[cx.id][cx.tim];
    Ans[g[cx.id][cx.tim]] = Rt;
  } else {
    long long sz = (n - 2) >> 1ll;
    for (; sz--;) {
      Node mx = q.top();
      q.pop();
      Node cx = q.top();
      q.pop();
      Ans[g[mx.id][mx.tim]] = g[cx.id][cx.tim];
      Ans[g[cx.id][cx.tim]] = g[mx.id][mx.tim];
      mx.tim++, cx.tim++, mx.sz--, cx.sz--;
      if (mx.sz) q.push(mx);
      if (cx.sz) q.push(cx);
    }
    Node mx = q.top();
    q.pop();
    Ans[Rt] = g[mx.id][mx.tim];
    Ans[g[mx.id][mx.tim]] = Rt;
  }
  io.write(ans), puts("");
  for (long long i = (1); i <= (n); i++) io.write(Ans[i]), putchar(' ');
  exit(0);
}
}  // namespace Big
signed main() {
  io.read(n);
  for (long long i = (1); i <= (n - 1); i++) {
    long long x, y;
    io.read(x), io.read(y);
    h[x].push_back(y), h[y].push_back(x);
  }
  Big::solve();
  return 0;
}
