#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[100001];
int res[100001], sub[100001];
long long k = 0;
vector<vector<int> > ord;
void computeSub(int u, int p) {
  sub[u] = 1;
  for (auto v : adj[u]) {
    if (v != p) {
      computeSub(v, u);
      sub[u] += sub[v];
    }
  }
}
int findCentroid(int u, int p, int o) {
  for (auto v : adj[u]) {
    if (v != p && sub[v] > sub[o] / 2) return findCentroid(v, u, o);
  }
  return u;
}
void dfs(int u, int p) {
  sub[u] = 1;
  if (p == -1) ord.push_back(vector<int>());
  ord.back().push_back(u);
  for (auto v : adj[u]) {
    if (p == -1) ord.push_back(vector<int>());
    if (v != p) {
      dfs(v, u);
      sub[u] += sub[v];
      k += 2 * sub[v];
    }
  }
}
bool comp(const vector<int> &a, const vector<int> &b) {
  return a.size() < b.size();
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    res[i] = -1;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u - 1].push_back(v - 1);
    adj[v - 1].push_back(u - 1);
  }
  computeSub(0, -1);
  int c = findCentroid(0, -1, 0);
  dfs(c, -1);
  sort(ord.begin(), ord.end(), comp);
  int j = ord.size() - 1, p = 0;
  for (int i = 0; i < ord.size(); i++) {
    for (int i2 = 0; i2 < ord[i].size(); i2++) {
      res[ord[i][i2]] = ord[j][p++];
      if (p == ord[j].size()) {
        j = (j + 1) % ord.size();
        p = 0;
      }
    }
  }
  cout << k << "\n";
  for (int i = 0; i < n; i++) {
    assert(res[i] > -1);
    cout << res[i] + 1;
    if (i + 1 < n) cout << " ";
  }
  return 0;
}
