#include <bits/stdc++.h>
const int M = 1e9 + 7, N = 2 * 1e5 + 3;
using namespace std;
long long f[N], n, sum, sum2, ans[N];
vector<long long> v[N], v0;
long long dfs2(int i, int j) {
  v0.push_back(i);
  long long cur = 1;
  for (auto l : v[i]) {
    if (l != j) cur += dfs2(l, i);
  }
  sum2 += min(cur, n - cur);
  return cur;
}
int main() {
  cin >> n;
  for (int i = 1, x, y; i < n; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs2(1, 0);
  cout << sum2 * 2 << "\n";
  for (int i = 0; i < n; i++) ans[v0[i]] = v0[(i + (n / 2)) % n];
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
