#include <bits/stdc++.h>
using namespace std;
int n, tot, root;
int t1, t2, t3, cnt;
int head[110000], nex[110000 << 1], to[110000 << 1], val[110000 << 1];
int size[110000], f[110000], pos[110000], fin[110000], num[110000];
multiset<pair<int, int> > s1;
multiset<pair<int, int> >::iterator it;
set<int> s2[110000];
set<int>::iterator it1;
int tr[110000 << 2], v[110000], p[110000 << 2];
long long ans;
void add(int x, int y, int z) {
  tot++;
  nex[tot] = head[x];
  head[x] = tot;
  to[tot] = y;
  val[tot] = z;
}
void dfs(int x, int y) {
  size[x] = 1;
  for (int i = head[x]; i; i = nex[i])
    if (to[i] != y) {
      dfs(to[i], x);
      size[x] += size[to[i]];
      f[x] = max(f[x], size[to[i]]);
    }
  f[x] = max(f[x], n - size[x]);
  if (f[x] < f[root]) root = x;
}
void dfs1(int x, int y, int v) {
  size[x] = 1;
  pos[x] = v;
  f[x] = min(f[x], x);
  s2[v].insert(x);
  for (int i = head[x]; i; i = nex[i])
    if (to[i] != y) {
      dfs1(to[i], x, v);
      size[x] += size[to[i]];
      f[x] = min(f[x], f[to[i]]);
    }
}
void dfs2(int x, int y, long long dis) {
  ans += dis * 2;
  for (int i = head[x]; i; i = nex[i])
    if (to[i] != y) dfs2(to[i], x, dis + val[i]);
}
void pushup(int x) {
  tr[x] = min(tr[x << 1], tr[x << 1 | 1]);
  p[x] = tr[x << 1] < tr[x << 1 | 1] ? p[x << 1] : p[x << 1 | 1];
}
void build(int l, int r, int now) {
  if (l == r) {
    tr[now] = v[l];
    p[now] = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, now << 1);
  build(mid + 1, r, now << 1 | 1);
  pushup(now);
}
pair<int, int> query(int l, int r, int now, int lq, int rq) {
  if (lq <= l && r <= rq) return make_pair(tr[now], p[now]);
  int mid = (l + r) >> 1;
  if (mid < lq) return query(mid + 1, r, now << 1 | 1, lq, rq);
  if (mid >= rq) return query(l, mid, now << 1, lq, rq);
  pair<int, int> t1 = query(l, mid, now << 1, lq, rq);
  pair<int, int> t2 = query(mid + 1, r, now << 1 | 1, lq, rq);
  return t1.first < t2.first ? t1 : t2;
}
void update(int l, int r, int now, int pos, int v) {
  if (l == r) {
    tr[now] = v;
    p[now] = l;
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= pos)
    update(l, mid, now << 1, pos, v);
  else
    update(mid + 1, r, now << 1 | 1, pos, v);
  pushup(now);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &t1, &t2, &t3);
    add(t1, t2, t3);
    add(t2, t1, t3);
  }
  f[0] = 1 << 30;
  dfs(1, 0);
  memset(f, 0x3f, sizeof(f));
  memset(tr, 0x3f, sizeof(tr));
  dfs2(root, 0, 0);
  cnt = 1;
  pos[root] = 1;
  s1.insert(make_pair(2, 1));
  s2[1].insert(root);
  v[1] = root;
  num[1] = 2;
  for (int i = head[root]; i; i = nex[i]) {
    dfs1(to[i], root, ++cnt);
    s1.insert(make_pair(size[to[i]] * 2, cnt));
    v[cnt] = f[to[i]];
    num[cnt] = size[to[i]] * 2;
  }
  build(1, cnt, 1);
  for (int i = 1; i <= n; i++) {
    int from;
    s1.erase(make_pair(num[pos[i]], pos[i]));
    it = s1.lower_bound(make_pair(n - i + 1, 0));
    if (it != s1.end() && (*it).first == n - i + 1 && (*it).second != 1)
      from = (*it).second;
    else {
      if (i == root)
        from = query(1, cnt, 1, 1, n).second;
      else {
        pair<int, int> t1 = make_pair(n + 1, 0), t2 = make_pair(n + 1, 0);
        if (pos[i] != 1) t1 = query(1, cnt, 1, 1, pos[i] - 1);
        if (pos[i] != cnt) t2 = query(1, cnt, 1, pos[i] + 1, n);
        from = t1.first < t2.first ? t1.second : t2.second;
      }
    }
    it1 = s2[from].begin();
    fin[i] = *it1;
    s2[from].erase(it1);
    s1.erase(make_pair(num[from], from));
    num[from]--;
    num[pos[i]]--;
    if (num[from]) s1.insert(make_pair(num[from], from));
    if (num[pos[i]]) s1.insert(make_pair(num[pos[i]], pos[i]));
    if (s2[from].size())
      update(1, cnt, 1, from, *s2[from].begin());
    else
      update(1, cnt, 1, from, n + 1);
  }
  printf("%I64d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", fin[i]);
  puts("");
  return 0;
}
