#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
int n, typ;
int first[N], nxt[N], to[N], w[N], ec;
void add(int x, int y, int z) {
  nxt[++ec] = first[x], first[x] = ec;
  to[ec] = y, w[ec] = z;
}
int in[N], out[N], tim, ic[N];
int blk[N];
int sz[N];
long long d[N];
int rt, Mx;
void fndrt(int u, int fa) {
  int mx = 0;
  sz[u] = 1;
  for (int e = first[u], v; e; e = nxt[e])
    if ((v = to[e]) != fa) {
      fndrt(v, u), sz[u] += sz[v];
      mx = max(mx, sz[v]);
    }
  mx = max(mx, n - sz[u]);
  if (mx < Mx) rt = u, Mx = mx;
}
void dfs(int u, int fa) {
  ic[in[u] = ++tim] = u, sz[u] = 1;
  for (int e = first[u], v; e; e = nxt[e])
    if ((v = to[e]) != fa) {
      d[v] = d[u] + w[e];
      dfs(v, u), sz[u] += sz[v];
    }
  out[u] = tim;
}
void col(int u, int fa, int r) {
  blk[in[u]] = r;
  for (int e = first[u], v; e; e = nxt[e])
    if ((v = to[e]) != fa) col(v, u, r);
}
namespace SGT {
const int N = ::N << 2;
int mn[N];
void up(int x) { mn[x] = min(mn[x << 1], mn[x << 1 | 1]); }
void build(int x, int l, int r) {
  if (l == r) return mn[x] = ic[l], void();
  build(x << 1, l, ((l + r) >> 1));
  build(x << 1 | 1, ((l + r) >> 1) + 1, r), up(x);
}
int ask(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return mn[x];
  int ans = n + 1;
  if (L <= ((l + r) >> 1)) ans = min(ans, ask(x << 1, l, ((l + r) >> 1), L, R));
  if (R > ((l + r) >> 1))
    ans = min(ans, ask(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R));
  return ans;
}
void lock(int x, int l, int r, int p) {
  if (l == r) return mn[x] = n + 1, void();
  if (p <= ((l + r) >> 1))
    lock(x << 1, l, ((l + r) >> 1), p);
  else
    lock(x << 1 | 1, ((l + r) >> 1) + 1, r, p);
  up(x);
}
}  // namespace SGT
int ask(int l, int r) {
  if (l > r) return n + 1;
  return SGT ::ask(1, 1, n, l, r);
}
set<pair<int, int> > S;
int main() {
  cin >> n;
  for (int i = 1, u, v, w; i < n; i++)
    scanf("%d%d%d", &u, &v, &w), add(u, v, w), add(v, u, w);
  Mx = n;
  fndrt(1, 0), dfs(rt, 0);
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += d[i];
  cout << ans * 2 << '\n';
  static int vl[N];
  blk[1] = rt;
  in[rt] = out[rt] = 1;
  for (int e = first[rt], v; e; e = nxt[e])
    v = to[e], col(v, rt, v), S.insert(make_pair(vl[v] = sz[v] * 2, v));
  SGT ::build(1, 1, n);
  for (int i = 1, x; i <= n; i++) {
    int r = blk[in[i]];
    x = -1;
    if (S.size()) {
      set<pair<int, int> >::iterator z = --S.end();
      if (z->first == n - i + 1 && r != z->second)
        x = ask(in[z->second], out[z->second]);
    }
    if (x == -1) {
      x = min(ask(1, in[r] - 1), ask(out[r] + 1, n));
      if (i == rt) x = min(x, ask(1, 1));
    }
    cout << x << " ";
    SGT ::lock(1, 1, n, in[x]);
    if (i == x) continue;
    int t = blk[in[x]];
    if (r != rt) S.erase(S.find(make_pair(vl[r], r)));
    if (t != rt) S.erase(S.find(make_pair(vl[t], t)));
    --vl[r], --vl[t];
    if (r != rt && vl[r] > 0) S.insert(make_pair(vl[r], r));
    if (t != rt && vl[t] > 0) S.insert(make_pair(vl[t], t));
  }
  return 0;
}
