#include <bits/stdc++.h>
using namespace std;
int sub[500005], dis[500005], to[500005], H[500005], anc[500005], size[500005],
    Cnt, cnt, nxt[500005], n, Anc[500005], res[500005], num[500005];
long long ans;
set<pair<int, int>, greater<pair<int, int> > > SZ;
set<int> S[500005];
set<pair<int, int> > T;
set<pair<int, int> >::iterator it;
void ins(int x, int y, int z) {
  to[++cnt] = y;
  dis[cnt] = z;
  nxt[cnt] = H[x];
  H[x] = cnt;
}
void center(int u, int fa) {
  size[u] = 1;
  int v;
  for (int i = H[u]; i; i = nxt[i])
    if ((v = to[i]) != fa) {
      center(v, u);
      size[u] += size[v];
      sub[u] = max(sub[u], size[v]);
    }
  sub[u] = max(sub[u], n - size[u]);
}
void dfs(int u, int fa, int anc) {
  size[u] = 1;
  Anc[u] = anc;
  if (anc) S[anc].insert(u);
  int v;
  for (int i = H[u]; i; i = nxt[i])
    if ((v = to[i]) != fa) {
      (!anc) ? dfs(v, u, ++Cnt) : dfs(v, u, anc);
      size[u] += size[v];
      ans += 2ll * dis[i] * size[v];
    }
}
void link(int x, int y) {
  int p = *S[y].begin();
  res[x] = p;
  T.erase(make_pair(p, y));
  SZ.erase(make_pair(num[y], y));
  if (x != p) SZ.erase(make_pair(num[Anc[x]], Anc[x]));
  S[y].erase(p);
  num[Anc[x]]--;
  num[y]--;
  if (S[y].size()) T.insert(make_pair(*S[y].begin(), y));
  if (x != p) SZ.insert(make_pair(num[y], y));
  SZ.insert(make_pair(num[Anc[x]], Anc[x]));
}
void work(int rt) {
  dfs(rt, 0, 0);
  S[0].insert(rt);
  for (int i = 1; i <= Cnt; ++i) T.insert(make_pair(*S[i].begin(), i));
  T.insert(make_pair(rt, 0));
  for (int i = 0; i <= Cnt; ++i)
    SZ.insert(make_pair(num[i] = S[i].size() * 2, i));
  int now = n;
  for (int i = 1; i <= n; ++i) {
    if (SZ.begin()->first == now-- && Anc[i] != SZ.begin()->second &&
        SZ.begin()->second != 0) {
      link(i, SZ.begin()->second);
      continue;
    }
    it = T.begin();
    if (i != rt && it->second == Anc[i]) it++;
    link(i, it->second);
  }
  cout << ans << endl;
  for (int i = 1; i <= n; ++i) printf("%d%c", res[i], i == n ? '\n' : ' ');
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    ins(u, v, w);
    ins(v, u, w);
  }
  center(1, 0);
  for (int i = 1; i <= n; ++i)
    if (sub[i] <= n / 2) return work(i), 0;
  return 0;
}
