#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline char gc() {
  static const int BS = 1 << 22;
  static unsigned char buf[BS], *st, *ed;
  if (st == ed) ed = buf + fread(st = buf, 1, BS, stdin);
  return st == ed ? EOF : *st++;
}
template <class T>
void in(T &x) {
  x = 0;
  bool f = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  if (f) x = -x;
}
int n;
int v[100010 << 1], w[100010 << 1], nx[100010 << 1];
int cnt, head[100010];
inline void add(int uu, int vv, int ww) {
  v[++cnt] = vv, w[cnt] = ww, nx[cnt] = head[uu];
  head[uu] = cnt;
}
int sz[100010];
int heav, mn = 0x3f3f3f3f;
void dfs(int x, int f) {
  sz[x] = 1;
  int mx = 0;
  for (register int i = head[x]; i; i = nx[i]) {
    if (v[i] == f) continue;
    dfs(v[i], x);
    sz[x] += sz[v[i]];
    mx = max(sz[v[i]], mx);
  }
  mx = max(n - sz[x], mx);
  if (mx < mn) {
    mn = mx;
    heav = x;
  }
}
set<int> tre[100010], mini;
set<pair<int, int> > io;
int sum[100010];
int bel[100010];
long long dep;
void efs(int x, int f, int b, long long d) {
  sz[x] = 1;
  dep += d;
  bel[x] = b;
  if (b) tre[b].insert(x);
  for (register int i = head[x]; i; i = nx[i]) {
    if (v[i] == f) continue;
    efs(v[i], x, b ? b : v[i], d + w[i]);
    sz[x] += sz[v[i]];
  }
  if (x == b) {
    mini.insert(*tre[x].begin());
    io.insert(make_pair(sum[x] = (sz[x] << 1), x));
  }
}
int solve(int x) {
  set<pair<int, int> >::iterator it = io.lower_bound(make_pair(n - x + 1, 0));
  bool free = 1;
  if (it != io.end() && it->first == n - x + 1 && it->second != bel[x])
    free = 0;
  if (bel[x]) {
    io.erase(make_pair(sum[bel[x]], bel[x]));
    io.insert(make_pair(--sum[bel[x]], bel[x]));
  }
  if (free) {
    int t = *mini.begin();
    if (bel[t] == bel[x] && x != heav) t = *(++mini.begin());
    mini.erase(t);
    if (bel[t]) {
      tre[bel[t]].erase(t);
      if (tre[bel[t]].size()) mini.insert(*tre[bel[t]].begin());
      io.erase(make_pair(sum[bel[t]], bel[t]));
      io.insert(make_pair(--sum[bel[t]], bel[t]));
    }
    return t;
  } else {
    int t = *tre[it->second].begin();
    mini.erase(t);
    tre[it->second].erase(t);
    if (tre[bel[t]].size()) mini.insert(*tre[bel[t]].begin());
    io.erase(make_pair(sum[bel[t]], bel[t]));
    io.insert(make_pair(--sum[bel[t]], bel[t]));
    return t;
  }
  return 0;
}
signed main() {
  in(n);
  for (register int i = 1, a, b, c; i < n; ++i) {
    in(a), in(b), in(c);
    add(a, b, c);
    add(b, a, c);
  }
  dfs(1, 0);
  efs(heav, 0, 0, 0);
  mini.insert(heav);
  dep <<= 1;
  printf("%lld\n", dep);
  for (register int i = 1; i <= n; ++i) {
    printf("%d ", solve(i));
  }
  return 0;
}
