#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int cnt, head[N], Max[N], size[N], rt, Ans[N], num[N], n, u, v, w, blo, anc[N];
long long ans, dis[N];
set<int> s[N];
set<pair<int, int> > SZ, T;
struct node {
  int to, next, w;
} Num[N * 2];
void add(int x, int y, int w) {
  Num[++cnt].to = y;
  Num[cnt].next = head[x];
  Num[cnt].w = w;
  head[x] = cnt;
}
void find_rt(int x, int fa) {
  size[x] = 1;
  for (int i = head[x]; i; i = Num[i].next)
    if (Num[i].to != fa) {
      find_rt(Num[i].to, x);
      size[x] += size[Num[i].to];
      Max[x] = max(Max[x], size[Num[i].to]);
    }
  Max[x] = max(Max[x], n - size[x]);
  if (Max[rt] > Max[x]) rt = x;
}
void dfs(int x, int fa, int Anc) {
  if (Anc) anc[x] = Anc, s[Anc].insert(x);
  ans += 2 * dis[x];
  for (int i = head[x]; i; i = Num[i].next)
    if (Num[i].to != fa) {
      dis[Num[i].to] = dis[x] + Num[i].w;
      if (!Anc)
        dfs(Num[i].to, x, ++blo);
      else
        dfs(Num[i].to, x, Anc);
    }
}
void link(int x, int y) {
  int p = *s[y].begin();
  SZ.erase(pair<int, int>(num[y], y));
  SZ.erase(pair<int, int>(num[anc[x]], anc[x]));
  T.erase(pair<int, int>(p, y));
  Ans[x] = p;
  s[y].erase(p);
  if ((int)s[y].size()) T.insert(pair<int, int>(*s[y].begin(), y));
  num[anc[x]]--;
  num[y]--;
  SZ.insert(pair<int, int>(num[y], y));
  SZ.insert(pair<int, int>(num[anc[x]], anc[x]));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++)
    scanf("%d%d%d", &u, &v, &w), add(u, v, w), add(v, u, w);
  Max[rt = 0] = n + 1;
  find_rt(1, -1);
  dfs(rt, 0, 0);
  s[0].insert(rt);
  for (int i = 0; i <= blo; i++)
    T.insert(pair<int, int>(*s[i].begin(), i)),
        num[i] = 2 * (int)s[i].size(), SZ.insert(pair<int, int>(num[i], i));
  for (int i = 1; i <= n; i++) {
    if (SZ.rbegin()->first == n - i + 1 && SZ.rbegin()->second != anc[i] &&
        SZ.rbegin()->second != 0)
      link(i, SZ.rbegin()->second);
    else {
      set<pair<int, int> >::iterator now = T.begin();
      if (i != rt && now->second == anc[i]) ++now;
      link(i, now->second);
    }
  }
  printf("%lld\n", ans);
  for (int i = 1; i <= n; i++) printf("%d%c", Ans[i], (i == n) ? 10 : 32);
  return 0;
}
