#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
template <typename T>
inline void read(T &x) {
  x = 0;
  char v = getchar();
  while (!(v >= '0' && v <= '9')) v = getchar();
  while ((v >= '0' && v <= '9')) {
    x = (x << 1) + (x << 3) + v - '0';
    v = getchar();
  }
}
template <typename T>
inline void write(T x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
struct miku {
  int u, v, w, next;
} MIKU[maxn << 1];
int Max = 1e9, gravity;
long long ans, dis[maxn];
int n, cnt, siz[maxn], h[maxn];
int top[maxn], rin, IA[maxn], AI[maxn];
set<pair<int, int> > s;
set<pair<int, int> >::iterator it;
struct tree {
  int l, r, Min;
} tre[maxn << 2];
inline void add(int u, int v, int w) {
  MIKU[++cnt].next = h[u];
  MIKU[cnt].u = u;
  MIKU[cnt].v = v;
  MIKU[cnt].w = w;
  h[u] = cnt;
}
inline void dfs(int x, int fa) {
  siz[x] = 1;
  int maxson = 0;
  for (int i = h[x]; i; i = MIKU[i].next) {
    int v = MIKU[i].v;
    if (v == fa) continue;
    dfs(v, x);
    siz[x] += siz[v];
    maxson = max(maxson, siz[v]);
  }
  maxson = max(maxson, n - siz[x]);
  if (maxson < Max) Max = maxson, gravity = x;
}
inline void dfs(int x, int fa, int topf) {
  top[x] = topf;
  siz[x] = 1;
  IA[x] = ++rin;
  for (int i = h[x]; i; i = MIKU[i].next) {
    int v = MIKU[i].v;
    if (v == fa) continue;
    dis[v] = dis[x] + MIKU[i].w;
    dfs(v, x, topf);
    siz[x] += siz[v];
  }
  AI[x] = rin;
}
inline void build(int pos, int l, int r) {
  tre[pos].l = l;
  tre[pos].r = r, tre[pos].Min = 0x3f3f3f3f;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(pos << 1, l, mid);
  build(pos << 1 | 1, mid + 1, r);
}
inline void change(int pos, int x, int k) {
  if (tre[pos].l == tre[pos].r) {
    tre[pos].Min = k;
    return;
  }
  int mid = (tre[pos].l + tre[pos].r) >> 1;
  if (x <= mid)
    change(pos << 1, x, k);
  else
    change(pos << 1 | 1, x, k);
  tre[pos].Min = min(tre[pos << 1].Min, tre[pos << 1 | 1].Min);
}
inline int ask(int pos, int l, int r) {
  if (l > r) return 0x3f3f3f3f;
  if (tre[pos].l == l && tre[pos].r == r) return tre[pos].Min;
  int mid = (tre[pos].l + tre[pos].r) >> 1;
  if (r <= mid)
    return ask(pos << 1, l, r);
  else if (l > mid)
    return ask(pos << 1 | 1, l, r);
  else
    return min(ask(pos << 1, l, mid), ask(pos << 1 | 1, mid + 1, r));
}
inline void Minus(int x) {
  s.erase(s.find(pair<int, int>(siz[x], x)));
  siz[x]--;
  s.insert(pair<int, int>(siz[x], x));
}
int main() {
  read(n);
  int u, v, w;
  for (int i = 1; i < n; i++) {
    read(u), read(v), read(w);
    add(u, v, w), add(v, u, w);
  }
  dfs(1, 0);
  memset(siz, 0, sizeof(siz));
  IA[gravity] = ++rin;
  for (int i = h[gravity]; i; i = MIKU[i].next) {
    int v = MIKU[i].v;
    dis[v] = dis[gravity] + MIKU[i].w;
    dfs(v, gravity, v);
    siz[gravity] += siz[v];
    siz[v] <<= 1;
  }
  siz[gravity]++;
  siz[gravity] <<= 1;
  for (int i = h[gravity]; i; i = MIKU[i].next) {
    int v = MIKU[i].v;
    s.insert(pair<int, int>(siz[v], v));
  }
  s.insert(pair<int, int>(siz[gravity], gravity));
  build(1, 1, n);
  AI[gravity] = IA[gravity];
  top[gravity] = gravity;
  for (int i = 1; i <= n; i++) ans += dis[i] << 1;
  write(ans), putchar('\n');
  for (int i = 1; i <= n; i++) change(1, IA[i], i);
  for (int i = 1, x; i <= n; i++) {
    Minus(top[i]);
    it = s.lower_bound(pair<int, int>(n - i + 1, 0));
    if (it != s.end() && it->first == n - i + 1)
      x = ask(1, IA[it->second], AI[it->second]);
    else
      x = min(ask(1, 1, IA[top[i]] - 1), ask(1, AI[top[i]] + 1, n)),
      x = min(x, ask(1, IA[gravity], IA[gravity]));
    write(x);
    putchar(' ');
    Minus(top[x]);
    change(1, IA[x], 0x3f3f3f3f);
  }
  return 0;
}
