#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod = 1e9 + 7, inf = 1e18;
int n = 1e5 + 5;
vvi adj(n);
vi sz(n);
vi subtrees;
vi pos(n);
ll ans = 0;
void dfs1(int i, int p) {
  sz[i] = 1;
  for (int c : adj[i]) {
    if (c != p) dfs1(c, i), sz[i] += sz[c];
  }
}
int dfs2(int i, int p) {
  for (int c : adj[i]) {
    if (c != p && sz[c] > sz[i] / 2) return dfs2(c, i);
  }
  return i;
}
void dfs3(int i, int p) {
  subtrees.push_back(i);
  pos[i] = (int)subtrees.size() - 1;
  for (int c : adj[i]) {
    if (c != p) {
      ans += min(sz[c], n - sz[c]) * 2;
      dfs3(c, i);
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[--u].push_back(--v), adj[v].push_back(u);
  }
  dfs1(0, -1);
  int cent = dfs2(0, -1);
  dfs1(cent, -1);
  dfs3(cent, -1);
  vi out(n);
  for (int i = 0; i < n; i++) {
    out[i] = subtrees[(pos[i] + n / 2) % n];
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << out[i] + 1 << " ";
  return 0;
}
