#include <bits/stdc++.h>
using namespace std;
int N, cent, out[100005];
long long ans;
vector<int> adj[100005], Ord;
int dfs1(int u, int prev) {
  int sz = 1, okay = 1;
  for (int v : adj[u]) {
    if (v == prev) {
      continue;
    }
    int res = dfs1(v, u);
    if (res > N / 2) {
      okay = false;
    }
    sz += res;
  }
  if (okay && sz > N / 2 && !cent) {
    cent = u;
  }
  return (sz);
}
int dfs2(int u, int prev) {
  int sz = 1;
  Ord.push_back(u);
  for (int v : adj[u]) {
    if (v == prev) {
      continue;
    }
    sz += dfs2(v, u);
  }
  if (prev) {
    ans += 2 * sz;
  }
  return (sz);
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i < N; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs1(1, 0);
  dfs2(cent, 0);
  for (int i = 0; i < N; i++) {
    out[Ord[i]] = Ord[(i + (N + 1) / 2) % N];
  }
  printf("%lld\n", ans);
  for (int i = 1; i <= N; i++) {
    printf("%d ", out[i]);
  }
}
