#include <bits/stdc++.h>
using namespace std;
long long siz[200005], sta[200005], son[200005], n, h[200005], ans, nex[200005],
    top, cnt, mx, rt;
struct l1 {
  long long to, next;
} p[400005];
void add(long long x, long long y) {
  cnt++;
  p[cnt].to = y;
  p[cnt].next = h[x];
  h[x] = cnt;
}
void dfs(long long x, long long fa) {
  siz[x] = 1;
  for (long long i = h[x]; i; i = p[i].next) {
    long long y = p[i].to;
    if (y == fa) continue;
    dfs(y, x);
    ans += min(siz[y], n - siz[y]);
    if (siz[y] > siz[son[x]]) son[x] = y;
    siz[x] += siz[y];
  }
  if (max(n - siz[x], siz[son[x]]) > mx) {
    mx = max(n - siz[x], siz[son[x]]);
    rt = x;
  }
}
void dfs1(long long x, long long fa) {
  sta[++top] = x;
  for (long long i = h[x]; i; i = p[i].next) {
    long long y = p[i].to;
    if (y == fa) continue;
    dfs1(y, x);
  }
}
int main() {
  scanf("%lld", &n);
  for (long long i = 1; i < n; i++) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  sta[++top] = rt;
  for (long long i = h[rt]; i; i = p[i].next) {
    dfs1(p[i].to, rt);
  }
  printf("%lld\n", ans * 2);
  for (long long i = 1; i <= n; i++) {
    nex[sta[i]] = sta[(i + n / 2 - 1) % n + 1];
  }
  for (long long i = 1; i <= n; i++) {
    printf("%lld ", nex[i]);
  }
}
