#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
vector<int> G[N], g[N];
int siz[N], a[N], b[N], mn[N];
int rt = 0;
long long ans = 0;
void dfs(int u, int f) {
  siz[u] = 1;
  for (int v : G[u]) {
    if (v == f) continue;
    dfs(v, u);
    siz[u] += siz[v];
    mn[u] = max(mn[u], siz[v]);
  }
  mn[u] = max(mn[u], n - siz[u]);
  if (mn[u] < mn[rt]) rt = u;
}
void dfs(int u, int f, int fr, int d) {
  ans += d * 2;
  g[fr].push_back(u);
  for (int v : G[u]) {
    if (v == f) continue;
    dfs(v, u, fr, d + 1);
  }
}
multiset<pair<int, int> > s;
inline void ins(int x) {
  if (g[x].size() > 0) s.insert({g[x].size(), x});
}
int main() {
  mn[0] = 1e9;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) a[i] = i;
  dfs(1, 0);
  for (int u : G[rt]) {
    dfs(u, rt, u, 1);
    s.insert({g[u].size(), u});
  }
  if (n & 1) {
    auto it1 = (--s.end());
    int x = it1->second;
    s.erase(it1);
    auto it2 = (--s.end());
    int y = it2->second;
    s.erase(it2);
    swap(a[g[x].back()], a[rt]);
    swap(a[rt], a[g[y].back()]);
    g[x].pop_back();
    g[y].pop_back();
    ins(x);
    ins(y);
  } else {
    auto it = (--s.end());
    int x = it->second;
    swap(a[g[x].back()], a[rt]);
    g[x].pop_back();
    s.erase(it);
    ins(x);
  }
  while (!s.empty()) {
    auto it1 = (--s.end());
    int x = it1->second;
    s.erase(it1);
    auto it2 = (--s.end());
    int y = it2->second;
    s.erase(it2);
    swap(a[g[x].back()], a[g[y].back()]);
    g[x].pop_back();
    g[y].pop_back();
    ins(x);
    ins(y);
  }
  for (int i = 1; i <= n; i++) b[a[i]] = i;
  printf("%lld\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", b[i]);
  return 0;
}
