#include <bits/stdc++.h>
using namespace std;
int n, x, y, z, X, T, rt, be[100005], s[100005], H[100005];
long long ans;
vector<int> a[100005], w[100005];
unordered_set<int> S[200005];
set<int> G, g[100005];
void dfs(int x, int y) {
  int tmp = 0;
  s[x] = 1;
  for (unsigned i = 0; i < a[x].size(); ++i)
    if (a[x][i] != y) {
      dfs(a[x][i], x);
      s[x] += s[a[x][i]];
      tmp = max(tmp, s[a[x][i]]);
    }
  tmp = max(tmp, n - s[x]);
  if (tmp < X) rt = x, X = tmp;
}
void go(int x, int y, long long h) {
  g[T].insert(x);
  be[x] = T;
  ans += h;
  for (unsigned i = 0; i < a[x].size(); ++i)
    if (a[x][i] != y) go(a[x][i], x, h + w[x][i]);
}
void POP(int k) {
  S[H[k]].erase(k);
  --H[k];
  S[H[k]].insert(k);
  if (S[X].empty()) --X;
  set<int>::iterator p = g[k].begin();
  G.erase(*p);
  printf("%d ", *p);
  g[k].erase(p);
  if (!g[k].empty()) G.insert(*g[k].begin());
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    a[x].push_back(y);
    a[y].push_back(x);
    w[x].push_back(z);
    w[y].push_back(z);
  }
  X = 1000000000;
  dfs(1, 0);
  X = 0;
  for (unsigned i = 0; i < a[rt].size(); ++i) {
    ++T;
    go(a[rt][i], rt, w[rt][i]);
    G.insert(*g[T].begin());
    H[T] = g[T].size() * 2;
    S[H[T]].insert(T);
    X = max(X, H[T]);
  }
  printf("%lld\n", ans * 2);
  G.insert(rt);
  for (int i = 1; i <= n; ++i) {
    if (n - i + 1 == X && be[i] != *S[X].begin())
      POP(*S[X].begin());
    else {
      set<int>::iterator k = G.begin();
      if (i != rt && be[*k] == be[i]) ++k;
      if (be[*k])
        POP(be[*k]);
      else {
        printf("%d ", rt);
        G.erase(rt);
      }
    }
    if (i == rt) continue;
    int k = be[i];
    S[H[k]].erase(k);
    --H[k];
    S[H[k]].insert(k);
    if (S[X].empty()) --X;
  }
  puts("");
  return 0;
}
