#include <bits/stdc++.h>
using namespace std;
long long n;
long long sz[100005];
long long ans[100005];
long long disc[100005];
long long tim = 0, res;
vector<long long> adj[100005];
void dfs(long long v = 0, long long p = -1) {
  sz[v] = 1;
  disc[v] = tim;
  ans[tim++] = v;
  for (long long u : adj[v]) {
    if (u == p) continue;
    dfs(u, v);
    res += 2 * min(sz[u], n - sz[u]);
    sz[v] += sz[u];
  }
}
signed main() {
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs();
  cout << res << '\n';
  for (long long i = 0; i < n; i++) {
    cout << ans[(disc[i] + n / 2) % n] + 1 << ' ';
  }
  cout << '\n';
  return 0;
}
