#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
long long n, si[N], dis[N], track_set_si[N], track_set_rest_si[N];
long long tot, fi[N], a[N << 1], ne[N << 1], c[N << 1];
struct Node {
  long long x, si, can_use_to_match;
  inline Node(long long si = 0, long long x = 0, long long can_use_to_match = 0)
      : x(x), si(si), can_use_to_match(can_use_to_match) {}
};
inline bool operator<(Node u, Node v) {
  return u.si + u.can_use_to_match == v.si + v.can_use_to_match
             ? u.x < v.x
             : u.si + u.can_use_to_match < v.si + v.can_use_to_match;
}
set<Node> st;
inline void Add(long long x, long long y, long long z) {
  a[++tot] = y;
  ne[tot] = fi[x];
  fi[x] = tot;
  c[tot] = z;
}
long long rt;
inline void GetHp(long long x, long long fa) {
  bool flag = 1;
  si[x] = 1;
  for (long long i = fi[x]; i; i = ne[i])
    if (a[i] != fa) {
      GetHp(a[i], x);
      si[x] += si[a[i]];
      if (si[a[i]] * 2 > n) flag = 0;
    }
  if ((n - si[x]) * 2 > n) flag = 0;
  if (flag) rt = x;
}
long long sum_dis;
inline void GetDis(long long x, long long fa, long long dis) {
  sum_dis += dis;
  si[x] = 1;
  for (long long i = fi[x]; i; i = ne[i])
    if (a[i] != fa) GetDis(a[i], x, dis + c[i]), si[x] += si[a[i]];
  track_set_rest_si[x] = track_set_si[x] = si[x];
}
long long dfn[N], ed_dfn[N], dclk, tp[N];
inline void GetDfn(long long x, long long fa, long long top) {
  dfn[x] = ++dclk;
  tp[x] = top;
  for (long long i = fi[x]; i; i = ne[i])
    if (a[i] != fa) GetDfn(a[i], x, top);
  ed_dfn[x] = dclk;
}
inline void EraseFromSet(long long x) {
  x = tp[x];
  st.erase(Node(track_set_si[x], x, track_set_rest_si[x]));
  st.insert(Node(--track_set_si[x], x, track_set_rest_si[x]));
}
inline void DecreaseMatchNum(long long x) {
  x = tp[x];
  st.erase(Node(track_set_si[x], x, track_set_rest_si[x]));
  st.insert(Node(track_set_si[x], x, --track_set_rest_si[x]));
}
namespace Seg {
const long long xb = N - 5;
long long f[N << 1];
inline void Set(long long x, long long y) {
  f[xb + x] = y;
  for (long long i = (xb + x) >> 1; i; i >>= 1)
    f[i] = min(f[i << 1], f[i << 1 | 1]);
}
inline long long Ask(long long x, long long y) {
  if (x > y) return 1e9;
  long long ans = 1e9;
  for (long long l = xb + x - 1, r = xb + y + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
    if (~l & 1) ans = min(ans, f[l ^ 1]);
    if (r & 1) ans = min(ans, f[r ^ 1]);
  }
  return ans;
}
}  // namespace Seg
signed main() {
  scanf("%lld", &n);
  for (long long i = 1, x, y, z; i < n; ++i) {
    scanf("%lld%lld%lld", &x, &y, &z);
    Add(x, y, z);
    Add(y, x, z);
  }
  GetHp(1, 0);
  assert(rt != 0);
  GetDis(rt, 0, 0);
  printf("%lld\n", sum_dis * 2);
  dfn[rt] = ed_dfn[rt] = ++dclk;
  track_set_rest_si[rt] = track_set_si[rt] = si[rt] = 1;
  tp[rt] = rt;
  st.insert(Node(0, rt, 0));
  for (long long i = fi[rt]; i; i = ne[i]) {
    GetDfn(a[i], rt, a[i]);
    st.insert(Node(si[a[i]], a[i], si[a[i]]));
  }
  for (long long i = 1; i <= n; ++i) Seg::Set(dfn[i], i);
  for (long long i = 1; i <= n; ++i) {
    Node now_max = *--st.end();
    long long mx = now_max.x, mxs = now_max.si;
    long long rst = n - i + 1 - now_max.can_use_to_match, match;
    if (tp[i] != mx && rst == mxs) {
      match = Seg::Ask(dfn[mx], ed_dfn[mx]);
    } else {
      if (i == rt) ed_dfn[i] = 0;
      match = min(Seg::Ask(1, dfn[tp[i]] - 1), Seg::Ask(ed_dfn[tp[i]] + 1, n));
    }
    printf("%lld ", match);
    cerr << ' ' << endl;
    Seg::Set(dfn[match], 1e9);
    EraseFromSet(match);
    DecreaseMatchNum(i);
  }
  puts("");
  return 0;
}
