#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r) { return l + rng() % (r - l + 1); }
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
const long long N = 1e5 + 10;
long long sz[N], ans[N], res, n;
vector<long long> ord, adj[N];
void dfs(long long x, long long par) {
  ord.push_back(x);
  sz[x] = 1;
  for (auto& i : adj[x])
    if (i != par) {
      dfs(i, x);
      sz[x] += sz[i];
    }
  res += min(sz[x], n - sz[x]);
}
signed main() {
  cin >> n;
  for (long long i = 1, _c = n - 1; i <= _c; ++i) {
    long long x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 1);
  cout << 2 * res << "\n";
  for (long long i = 1, _c = n; i <= _c; ++i)
    ans[ord[(i - 1 + n / 2) % n]] = ord[i - 1];
  for (long long i = 1, _c = n; i <= _c; ++i) cout << ans[i] << " ";
}
