#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
vector<int> v[maxn];
int SZ[maxn];
void dfsSZ(int u, int par = -1) {
  SZ[u] = 1;
  for (int y : v[u])
    if (y != par) dfsSZ(y, u), SZ[u] += SZ[y];
}
int center(int u, int N, int par = -1) {
  for (int y : v[u])
    if (y != par && SZ[y] > N) return center(y, N, u);
  return u;
}
long long ANS;
int ans[maxn];
vector<int> vec;
void dfs(int u, int par = -1) {
  vec.push_back(u);
  for (int y : v[u])
    if (y != par) ANS += 2 * SZ[y], dfs(y, u);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie();
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfsSZ(1);
  int r = center(1, n / 2);
  dfsSZ(r);
  dfs(r);
  for (int i = 0; i < n; i++) {
    ans[vec[i]] = vec[(i + (n / 2)) % n];
  }
  cout << ANS << "\n";
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return cout << endl, 0;
}
