#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > graph;
vector<int> p, cnt;
void dfs(int start, int pa) {
  cnt[start] = 1;
  p.push_back(start);
  for (auto i : graph[start]) {
    if (i != pa) {
      dfs(i, start);
      cnt[start] += cnt[i];
    }
  }
}
int main() {
  int n, i, x, y;
  scanf("%d", &n);
  cnt.assign(n + 1, 0);
  graph.assign(n + 1, vector<int>());
  for (i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  dfs(1, 0);
  long long int ans = 0ll;
  for (i = 1; i <= n; i++) {
    for (auto j : graph[i]) {
      if (cnt[i] > cnt[j]) {
        ans = ans + min(cnt[j], n - cnt[j]);
      } else {
        ans = ans + min(cnt[i], n - cnt[i]);
      }
    }
  }
  printf("%lld\n", ans);
  int res[n + 1];
  for (i = 0; i < n; i++) {
    res[p[i]] = p[(i + n / 2) % n];
  }
  for (i = 1; i <= n; i++) printf("%d ", res[i]);
}
