#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<int> g[N];
int sz[N];
long long sum = 0;
int n;
int get_sz(int u, int p) {
  sz[u] = 1;
  for (int e : g[u]) {
    if (e == p) continue;
    sz[u] += get_sz(e, u);
  }
  return sz[u];
}
int find(int u, int p) {
  for (int e : g[u]) {
    if (e == p) continue;
    if (sz[e] > n / 2) return find(e, u);
  }
  return u;
}
int euler[N], found[N], ans[N];
int t;
void tour(int u, int p) {
  found[u] = t;
  euler[t] = u;
  ++t;
  for (int e : g[u]) {
    if (e == p) continue;
    tour(e, u);
  }
}
void solve() {
  scanf("%d", &n);
  for (int i = (1); i <= (n - 1); ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  get_sz(1, 1);
  int root = find(1, 1);
  get_sz(root, root);
  for (int i = (1); i <= (n); ++i)
    if (i != root) sum += sz[i];
  tour(root, root);
  for (int i = (1); i <= (n); ++i) {
    ans[i] = euler[(found[i] + n / 2) % n];
  }
  printf("%lld\n", sum << 1);
  for (int i = (1); i <= (n); ++i) printf("%d ", ans[i]);
}
int main() {
  solve();
  return 0;
}
