#include <bits/stdc++.h>
using namespace std;
const int N = 214514;
struct edge {
  int v, nt;
  long long w;
} e[N << 1];
set<int> tr[N], s;
set<pair<int, int>> id;
int hd[N], sz[N], rt[N];
int n, k, w = 1e9, tot, po, ct;
long long kkr;
void add(int x, int y, int z) {
  e[++tot] = {y, hd[x], z};
  hd[x] = tot;
}
void dfs(int x, int f) {
  sz[x] = 1;
  int m = 0;
  for (int i = hd[x]; i; i = e[i].nt) {
    int to = e[i].v;
    if (to == f) continue;
    dfs(to, x);
    m = max(sz[to], m);
    sz[x] += sz[to];
    kkr += 2 * e[i].w * min(sz[to], n - sz[to]);
  }
  if (w > max(m, n - sz[x])) w = max(m, n - sz[x]), k = x;
}
void ycl(int x, int f) {
  tr[rt[x] = po].insert(x);
  sz[po] += 2;
  for (int i = hd[x]; i; i = e[i].nt)
    if (e[i].v != f) ycl(e[i].v, x);
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y, z; i < n; i++) {
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z);
    add(y, x, z);
  }
  dfs(1, 0);
  tr[rt[k] = ++po].insert(k), s.insert(k);
  printf("%lld\n", kkr);
  id.insert({1, 1});
  sz[1] = 1;
  for (int i = hd[k]; i; i = e[i].nt) {
    sz[++po] = 0, ycl(e[i].v, k), s.insert(*tr[po].begin()),
    id.insert({sz[po], po});
  }
  for (int i = 1; i <= n; i++) {
    int x, md = id.rbegin()->second, mc = id.rbegin()->first;
    if (mc == n - i + 1 && rt[i] != md)
      x = *tr[md].begin();
    else if (rt[i] != rt[*s.begin()] || i == k)
      x = *s.begin();
    else
      x = *++s.begin();
    tr[rt[x]].erase(x);
    s.erase(x);
    if (!tr[rt[x]].empty()) s.insert(*tr[rt[x]].begin());
    if (i != k) id.erase({sz[rt[i]], rt[i]}), id.insert({--sz[rt[i]], rt[i]});
    if (x != k) id.erase({sz[rt[x]], rt[x]}), id.insert({--sz[rt[x]], rt[x]});
    printf("%d ", x);
  }
}
