#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, used[N], vin[N], ans1[N], ans2[N], sz[N], sum1, cnt[N];
long long sum2;
vector<int> g[N], d;
void dfs(int v, int p) {
  vin[v] = v;
  sz[v] = g[v].size();
  cnt[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) continue;
    dfs(to, v);
    sz[v]--;
    cnt[v] += cnt[to];
  }
  d.push_back(v);
  sum2 += min(cnt[v], n - cnt[v]);
  if (!used[v] || (v != p && sz[p] == 1 && !used[p])) {
    swap(vin[v], vin[p]);
    ans1[vin[p]] = p;
    ans1[vin[v]] = v;
    used[v] = used[p] = 1;
    sum1 += 2;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 1);
  for (int i = 0; i < n; i++) ans2[d[i]] = d[(i + n / 2) % n];
  cout << sum2 + sum2 << endl;
  for (int i = 1; i <= n; i++) cout << ans2[i] << " ";
  cout << endl;
  return 0;
}
