#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  out << p.first << ' ' << p.second;
  return out;
}
template <class T1, class T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <class T>
istream& operator>>(istream& in, vector<T>& v) {
  for (auto& x : v) in >> x;
  return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<vector<T>>& v) {
  for (auto& x : v) out << x << '\n';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  for (auto x : v) out << x << ' ';
  return out;
}
const long long N = 1e5 + 5;
long long n, ans;
vector<long long> seq;
vector<long long> g[N], second(N), res(N);
void cal(long long u, long long par) {
  second[u] = 1;
  for (auto v : g[u]) {
    if (v == par) continue;
    cal(v, u);
    second[u] += second[v];
  }
  ans += min(second[u], n - second[u]);
}
long long centroid(long long u, long long par) {
  for (auto v : g[u]) {
    if (v == par) continue;
    if (2 * second[v] >= n) return centroid(v, u);
  }
  return u;
}
void dfs(long long u, long long par) {
  seq.push_back(u);
  for (auto v : g[u]) {
    if (v == par) continue;
    dfs(v, u);
  }
}
void solve() {
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  cal(0, -1);
  long long c = centroid(0, -1);
  dfs(c, -1);
  cout << 2 * ans << "\n";
  for (long long i = 0; i < n; i++) res[seq[i]] = seq[(i + n / 2) % n] + 1;
  for (long long i = 0; i < n; i++) cout << res[i] << " ";
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cerr.tie(0);
  ;
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
