#include <bits/stdc++.h>
template <class Q>
inline void read(Q& x) {
  register int f, c;
  f = 1;
  while (c = getchar(), c < 48 || c > 57)
    if (c == '-') f = -1;
  for (x = 0; c > 47 && c < 58; c = getchar()) x = x * 10 + c - 48;
  x *= f;
}
const int max_N = 1e5;
int n, siz[max_N + 21], max[max_N + 21], centriod;
std::vector<std::pair<int, int>> vec[max_N + 21];
inline void add_edge() {
  register int u, v, w;
  read(u), read(v), read(w);
  vec[u].push_back({v, w});
  vec[v].push_back({u, w});
}
void get_centriod(int x, int p) {
  siz[x] = 1, max[x] = 0;
  for (auto& e : vec[x]) {
    int& y = e.first;
    if (y == p) continue;
    get_centriod(y, x);
    siz[x] += siz[y];
    max[x] = std::max(max[x], siz[y]);
  }
  max[x] = std::max(max[x], n - siz[x]);
  if (max[centriod] > max[x]) centriod = x;
}
long long ans1;
void get_ans1(int x, int p, long long dis) {
  ans1 += dis;
  for (auto& e : vec[x])
    if (e.first != p) get_ans1(e.first, x, dis + e.second);
}
std::set<std::pair<int, int>> set;
std::set<int> right, rights[max_N + 21];
int cnt, belong[max_N + 21];
void dfs(int x, int p, int id) {
  belong[x] = id;
  rights[id].insert(x);
  ++siz[id];
  for (auto& e : vec[x])
    if (e.first != p) dfs(e.first, x, id);
}
int ans[max_N + 21];
inline void del_right(int x) {
  right.erase(x);
  if (x == centriod) return;
  int y = belong[x];
  rights[y].erase(x);
  if (!rights[y].empty()) right.insert(*rights[y].begin());
  set.erase({siz[y], y});
  set.insert({--siz[y], y});
}
inline void del_left(int x) {
  int y = belong[x];
  set.erase({siz[y], y});
  set.insert({--siz[y], y});
}
int main() {
  read(n);
  for (int i = (2); i <= (n); ++i) add_edge();
  max[centriod = 0] = n + 1;
  get_centriod(1, 0);
  get_ans1(centriod, 0, 0);
  ans1 <<= 1;
  printf("%I64d\n", ans1);
  for (int i = (0); i <= (n); ++i) siz[i] = 0;
  right.insert(centriod);
  rights[0].insert(centriod);
  for (auto& e : vec[centriod]) {
    int y = e.first;
    dfs(y, centriod, ++cnt);
    siz[cnt] <<= 1;
    right.insert(*rights[cnt].begin());
    set.insert({siz[cnt], cnt});
  }
  for (int i = 1; i <= n; del_left(i), del_right(ans[i]), ++i) {
    if (!set.empty()) {
      auto x = *--set.end();
      if (x.first == n - i + 1 && x.second != belong[i]) {
        ans[i] = *rights[x.second].begin();
        continue;
      }
    }
    auto it = right.begin();
    if (i != centriod && belong[*it] == belong[i]) ++it;
    ans[i] = *it;
  }
  for (int i = (1); i <= (n); ++i) printf("%d%c", ans[i], i == n ? '\n' : ' ');
  return 0;
}
