#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > tree;
vector<int> sts;
vector<int> ans;
long long val = 0;
int centroid = -1;
int n;
void dfs(int cur, int par) {
  bool bad = false;
  for (auto a : tree[cur]) {
    if (a != par) {
      dfs(a, cur);
      sts[cur] += sts[a];
      if (sts[a] > n / 2) bad = true;
    }
  }
  if (!bad && n - sts[cur] <= n / 2) centroid = cur;
}
vector<int> cl;
void dfs2(int cur, int par) {
  cl.push_back(cur);
  sts[cur] = 1;
  for (auto a : tree[cur]) {
    if (a != par) {
      dfs2(a, cur);
      sts[cur] += sts[a];
    }
  }
  if (par == -1) {
    for (int i = 0; i < cl.size(); i++) {
      ans[cl[i]] = cl[(i + n / 2) % n];
    }
    for (int i = 0; i < n; i++) {
      if (i != cur) val += sts[i] * 2;
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin >> n;
  tree.resize(n);
  ans.resize(n, -1);
  sts.resize(n, 1);
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    tree[a - 1].push_back(b - 1);
    tree[b - 1].push_back(a - 1);
  }
  dfs(0, -1);
  dfs2(centroid, -1);
  cout << val << "\n";
  for (auto a : ans) cout << a + 1 << " ";
  cout << endl;
}
