#include <bits/stdc++.h>
long long gi() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
std::mt19937 rnd(time(NULL));
template <class T>
void cxk(T& a, T b) {
  a = a > b ? a : b;
}
template <class T>
void cnk(T& a, T b) {
  a = a < b ? a : b;
}
int fir[100010], dis[200010], nxt[200010], w[200010], id;
void link(int a, int b, int c) {
  nxt[++id] = fir[a], fir[a] = id, dis[id] = b, w[id] = c;
}
int ff[100010], sz[100010], rt, n;
void getrt(int x, int fa = -1) {
  sz[x] = 1;
  ff[x] = 0;
  for (int i = fir[x]; i; i = nxt[i]) {
    if (fa == dis[i]) continue;
    getrt(dis[i], x);
    cxk(ff[x], sz[dis[i]]);
    sz[x] += sz[dis[i]];
  }
  cxk(ff[x], n - sz[x]);
  if (ff[x] < ff[rt]) rt = x;
}
int siz[100010], from[100010];
long long ans = 0;
void dfs(int x, int fa = -1, int faw = 0) {
  siz[x] = 1;
  for (int i = fir[x]; i; i = nxt[i]) {
    if (fa == dis[i]) continue;
    if (fa == -1)
      from[dis[i]] = dis[i];
    else
      from[dis[i]] = from[x];
    dfs(dis[i], x, w[i]);
    siz[x] += siz[dis[i]];
  }
  ans += 1ll * siz[x] * faw;
}
std::set<int> in[100010];
int out[100010];
std::set<std::pair<int, int> > All;
std::set<int> mn;
int main() {
  n = gi();
  int u, v, w;
  for (int i = 1; i < n; ++i)
    u = gi(), v = gi(), w = gi(), link(u, v, w), link(v, u, w);
  ff[0] = 1e9, getrt(1);
  from[rt] = rt;
  dfs(rt);
  printf("%lld\n", ans << 1);
  for (int i = 1; i <= n; ++i) in[from[i]].insert(i), ++out[from[i]];
  for (int i = 1; i <= n; ++i)
    if (in[i].size())
      All.insert({in[i].size() + out[i], i}), mn.insert(*in[i].begin());
  for (int i = 1; i <= n; ++i) {
    int y;
    if (All.rbegin()->first == n - i + 1 && from[i] != All.rbegin()->second &&
        rt != All.rbegin()->second)
      y = *in[All.rbegin()->second].begin();
    else {
      y = *mn.begin();
      if (from[y] == from[i] && i != rt) y = *++mn.begin();
    }
    printf("%d ", y);
    All.erase({in[from[y]].size() + out[from[y]], from[y]});
    mn.erase(y);
    in[from[y]].erase(y);
    All.insert({in[from[y]].size() + out[from[y]], from[y]});
    if (in[from[y]].size()) mn.insert(*in[from[y]].begin());
    All.erase({in[from[i]].size() + out[from[i]], from[i]});
    --out[from[i]];
    All.insert({in[from[i]].size() + out[from[i]], from[i]});
  }
  return 0;
}
