#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> G[maxn], tour;
int n, sz[maxn], ans[maxn], pre[maxn], nex[maxn];
long long res;
void DFS(int u, int par = 0) {
  sz[u] = 1;
  for (auto v : G[u]) {
    if (v == par) continue;
    DFS(v, u);
    sz[u] += sz[v];
  }
}
void DFS_tour(int u, int par = 0) {
  tour.push_back(u);
  sz[u] = 1;
  for (auto v : G[u]) {
    if (v == par) continue;
    DFS_tour(v, u);
    sz[u] += sz[v];
  }
  res += 2 * min(sz[u], n - sz[u]);
}
int Get_Centroid(int u, int par = 0) {
  for (auto v : G[u]) {
    if (v == par) continue;
    if (sz[v] * 2 > n) return Get_Centroid(v, u);
  }
  return u;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cerr << "Processing...\n\n";
  if (fopen(""
            ".INP",
            "r")) {
    freopen(
        ""
        ".INP",
        "r", stdin);
  }
  cin >> n;
  for (int u, v, i = 1; i < n; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  DFS(1);
  int cent = Get_Centroid(1, 0);
  DFS_tour(cent);
  for (int i = 0; i < n; i++) ans[tour[i]] = tour[(i + n / 2) % n];
  cout << res << "\n";
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  cerr << "\n\n-----------------\n";
  return 0;
}
