#include <bits/stdc++.h>
using namespace std;
const long long MAX_NOEUDS = (100 * 1000);
vector<pair<long long, long long>> Voisins[MAX_NOEUDS];
long long Num[MAX_NOEUDS];
long long Ordre[MAX_NOEUDS];
long long cur = 0;
long long distTot = 0;
long long nbNoeuds;
void Read() {
  scanf("%lld", &nbNoeuds);
  for (long long i = 1; i < nbNoeuds; i++) {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    Voisins[--a].push_back(make_pair(--b, 0));
    Voisins[b].push_back(make_pair(a, 0));
  }
  return;
}
long long NbFils(long long noeud, long long pere) {
  long long sum = 1;
  for (long long i = 0; i < (long long)Voisins[noeud].size(); i++) {
    if (Voisins[noeud][i].first != pere) {
      Voisins[noeud][i].second = NbFils(Voisins[noeud][i].first, noeud);
      sum += Voisins[noeud][i].second;
    }
  }
  for (long long i = 0; i < (long long)Voisins[noeud].size(); i++) {
    if (Voisins[noeud][i].first == pere) {
      Voisins[noeud][i].second = nbNoeuds - sum;
    }
  }
  return sum;
}
long long FindCentroide(long long noeud) {
  for (pair<long long, long long> dest : Voisins[noeud]) {
    if (dest.second > nbNoeuds / 2) {
      return FindCentroide(dest.first);
    }
  }
  return noeud;
}
void Ordonne(long long noeud, long long pere) {
  Num[noeud] = cur;
  Ordre[cur++] = noeud;
  for (pair<long long, long long> dest : Voisins[noeud]) {
    if (dest.first != pere) {
      Ordonne(dest.first, noeud);
    }
  }
  return;
}
void Solve() {
  NbFils(0, -1);
  for (long long i = 0; i < nbNoeuds; i++) {
    for (pair<long long, long long> dest : Voisins[i]) {
      distTot += min(dest.second, nbNoeuds - dest.second);
    }
  }
  long long cent = FindCentroide(0);
  Ordonne(cent, -1);
  printf("%lld\n", distTot);
  for (long long i = 0; i < nbNoeuds; i++) {
    printf("%lld ", Ordre[(Num[i] + (nbNoeuds / 2)) % nbNoeuds] + 1);
  }
  printf("\n");
  return;
}
signed main() {
  Read();
  Solve();
  return 0;
}
