#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<int> g[N];
long long cost = 0;
int n;
int sz[N], max_subtree_size[N];
void dfs(int x, int fa) {
  sz[x] = 1;
  max_subtree_size[x] = 0;
  for (auto y : g[x]) {
    if (y == fa) continue;
    dfs(y, x);
    max_subtree_size[x] = max(max_subtree_size[x], sz[y]);
    sz[x] += sz[y];
  }
  max_subtree_size[x] = max(max_subtree_size[x], n - sz[x]);
}
int dfs_order[N], dfs_index = 0;
pair<int, int> dfs_order_range[N];
void dfs2(int x, int fa, int dep) {
  cost += dep << 1;
  dfs_order[++dfs_index] = x;
  dfs_order_range[x].first = dfs_index;
  for (auto y : g[x]) {
    if (y == fa) continue;
    dfs2(y, x, dep + 1);
  }
  dfs_order_range[x].second = dfs_index;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0);
  int root = 0;
  for (int i = 1; i <= n; ++i) {
    if (max_subtree_size[i] > n / 2) continue;
    root = i;
    break;
  }
  dfs2(root, 0, 0);
  if (0) printf("root = %d\n", root);
  printf("%lld\n", cost);
  for (int i = 1; i <= n; ++i)
    printf("%d%c", dfs_order[(dfs_order_range[i].first + n / 2 - 1) % n + 1],
           " \n"[i == n]);
  return 0;
}
