#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
long long T, n, ans, ind[100005], sub[100005];
vector<long long> e[100005], rr, ord;
void dfs(long long g, long long p) {
  sub[g] = 1;
  ind[g] = (int)ord.size();
  ord.push_back(g);
  for (auto u : e[g]) {
    if (u == p) continue;
    dfs(u, g);
    ans += 2LL * min(sub[u], n - sub[u]);
    sub[g] += sub[u];
  }
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    long long t1, t2;
    cin >> t1 >> t2;
    e[t1].push_back(t2);
    e[t2].push_back(t1);
  }
  dfs(1, 0);
  cout << ans << '\n';
  for (int i = 1; i <= n; i++) cout << ord[(ind[i] + n / 2) % n] << ' ';
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  T = 1;
  for (int t = 1; t <= T; t++) solve();
  cout.flush();
  return 0;
}
