#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
const int oo = 2e9;
set<array<int, 2> > setik, oth;
vector<int> g[N], vc;
int n, siz[N], cen, who_kto[N];
long long ans;
void build_sz(int v, int p) {
  siz[v] = 1;
  for (int u : g[v]) {
    if (u == p) continue;
    build_sz(u, v);
    siz[v] += siz[u];
    ans += min(siz[u], n - siz[u]);
  }
}
int search(int v, int p, int SZ) {
  for (int u : g[v])
    if (u != p && siz[u] > SZ / 2) return search(u, v, SZ);
  return v;
}
void add(int v, int p) {
  vc.push_back(v);
  for (int u : g[v]) {
    if (u == p) continue;
    add(u, v);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  build_sz(0, -1);
  cout << ans * 2 << '\n';
  cen = search(0, -1, siz[0]);
  for (int u : g[cen]) add(u, cen);
  vc.push_back(cen);
  for (int i = 0; i < n; i++) who_kto[vc[i]] = vc[(i + n / 2) % n];
  for (int i = 0; i < n; i++) cout << who_kto[i] + 1 << " ";
  return 0;
}
