#include <bits/stdc++.h>
using namespace std;
long long n, a, b, pos, val[100005], sol[100005], c, ans, fat[100005];
vector<int> grafo[100005], v;
bool comp(int a, int b) { return val[a] > val[b]; }
void dfs(int nodo, int last, int mode, int depth) {
  if (mode == 1) {
    v.push_back(nodo);
    ans += depth;
  }
  fat[nodo] = last;
  val[nodo] = 1;
  sort(grafo[nodo].begin(), grafo[nodo].end(), comp);
  for (int i = 0; i < grafo[nodo].size(); i++) {
    if (grafo[nodo][i] != last) {
      dfs(grafo[nodo][i], nodo, mode, depth + 1);
      val[nodo] += val[grafo[nodo][i]];
    }
  }
  if (val[nodo] >= (n + 1) / 2 && pos == -1) {
    pos = nodo;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    grafo[a].push_back(b);
    grafo[b].push_back(a);
  }
  pos = -1;
  dfs(1, -1, 0, 0);
  val[fat[pos]] = n - val[pos];
  dfs(pos, -1, 1, 0);
  if (n % 2 == 1) {
    a = v[0];
    v.erase(v.begin());
    b = v[0];
    v.erase(v.begin());
    c = v.back();
    v.pop_back();
    sol[a] = b;
    sol[b] = c;
    sol[c] = a;
  }
  for (int i = 0; i < v.size() / 2; i++) {
    sol[v[i]] = v[i + v.size() / 2];
    sol[v[i + v.size() / 2]] = v[i];
  }
  cout << ans * 2 << "\n";
  for (int i = 1; i <= n; i++) cout << sol[i] << " ";
  cout << "\n";
  return 0;
}
