#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& os, pair<A, B> p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class A>
ostream& operator<<(ostream& os, vector<A> v) {
  os << "{ ";
  for (auto& x : v) cout << x << " ";
  return os << "}";
}
template <class A>
ostream& operator<<(ostream& os, vector<vector<A>> v) {
  os << "{ " << v.front() << '\n';
  for (auto it = next(v.begin()); it != v.end(); it++)
    os << "  " << *it << '\n';
  return os << "}";
}
using VI = vector<int>;
using VVI = vector<VI>;
using II = pair<int, int>;
using VII = vector<II>;
using L = long long;
using VL = vector<L>;
using VB = vector<bool>;
using VVB = vector<VB>;
int n, centroid;
L ans = 0;
VI spis;
VVI graph;
void dfs_spis(int v, int f) {
  spis.emplace_back(v);
  for (auto u : graph[v])
    if (u != f) dfs_spis(u, v);
}
int dfs(int v = 0, int f = -1) {
  int sz = 1;
  bool centro = true;
  for (auto u : graph[v])
    if (u != f) {
      int sz_u = dfs(u, v);
      centro = centro and (2 * sz_u <= n);
      sz += sz_u;
    }
  centro = centro and (2 * sz >= n - 2);
  if (v) ans += min(sz, n - sz);
  if (centro) centroid = v;
  return sz;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  graph.resize(n);
  for (decltype((n - 1) - 1) i = (0), i__ = ((n - 1) - 1); i <= i__; i++) {
    int u, v;
    cin >> u >> v;
    graph[u - 1].emplace_back(v - 1);
    graph[v - 1].emplace_back(u - 1);
  }
  dfs();
  cout << 2 * ans << "\n";
  ;
  spis = {centroid};
  for (auto v : graph[centroid]) dfs_spis(v, centroid);
  VI out(n);
  for (decltype((n)-1) i = (0), i__ = ((n)-1); i <= i__; i++)
    out[spis[i]] = spis[(i + (n / 2)) % n] + 1;
  for (decltype((n)-1) i = (0), i__ = ((n)-1); i <= i__; i++)
    cout << out[i] << " ";
  cout << "\n";
}
