#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int first[maxn], nxt[maxn], vv[maxn];
int Min[maxn << 2], Max[maxn << 2];
int sum[maxn], top[maxn], siz[maxn], fa[maxn];
vector<int> V[maxn];
void dfs1(int n) {
  siz[n] = 1;
  for (int e = first[n]; e; e = nxt[e])
    if (vv[e] - fa[n]) {
      fa[vv[e]] = n;
      dfs1(vv[e]);
      siz[n] += siz[vv[e]];
    }
}
int getRoot(int n) {
  dfs1(1);
  int i, ret = 0, ans, j;
  for (i = 1; i <= n; i++) {
    j = n - siz[i];
    for (int e = first[i]; e; e = nxt[e])
      if (fa[vv[e]] == i) j = max(j, siz[vv[e]]);
    if (ret == 0 || ans > j) ret = i, ans = j;
  }
  return ret;
}
int lft[maxn << 2], rht[maxn << 2];
void flow(int n) {
  if (lft[n] == rht[n]) return;
  if (top[Min[n << 1]] < top[Min[(n << 1) + 1]])
    Min[n] = Min[n << 1];
  else
    Min[n] = Min[(n << 1) + 1];
  if (sum[Max[n << 1]] > sum[Max[(n << 1) + 1]])
    Max[n] = Max[n << 1];
  else
    Max[n] = Max[(n << 1) + 1];
}
void build(int n, int l, int r) {
  lft[n] = l, rht[n] = r;
  if (l == r) {
    Min[n] = Max[n] = l;
    return;
  }
  int mid = (l + r) / 2;
  build(n << 1, l, mid);
  build((n << 1) + 1, mid + 1, r);
  flow(n);
}
void upd_sum(int n, int pos, int v) {
  if (lft[n] == rht[n]) {
    sum[lft[n]] = v;
    return;
  }
  int mid = (lft[n] + rht[n]) / 2;
  if (pos <= mid)
    upd_sum(n << 1, pos, v);
  else
    upd_sum((n << 1) + 1, pos, v);
  flow(n);
}
void upd_top(int n, int pos) {
  if (lft[n] == rht[n]) {
    V[lft[n]].pop_back();
    top[lft[n]] = V[lft[n]][V[lft[n]].size() - 1];
    return;
  }
  int mid = (lft[n] + rht[n]) / 2;
  if (pos <= mid)
    upd_top(n << 1, pos);
  else
    upd_top((n << 1) + 1, pos);
  flow(n);
}
int get_top(int n, int l, int r) {
  if (lft[n] == l && rht[n] == r) return Min[n];
  int mid = (lft[n] + rht[n]) / 2;
  if (r <= mid)
    return get_top(n << 1, l, r);
  else if (l > mid)
    return get_top((n << 1) + 1, l, r);
  l = get_top(n << 1, l, mid);
  r = get_top((n << 1) + 1, mid + 1, r);
  return top[l] < top[r] ? l : r;
}
int get_sum(int n, int l, int r) {
  if (lft[n] == l && rht[n] == r) return Max[n];
  int mid = (lft[n] + rht[n]) / 2;
  if (r <= mid)
    return get_sum(n << 1, l, r);
  else if (l > mid)
    return get_sum((n << 1) + 1, l, r);
  l = get_sum(n << 1, l, mid);
  r = get_sum((n << 1) + 1, mid + 1, r);
  return sum[l] > sum[r] ? l : r;
}
int bel[maxn], cnt;
void dfs2(int n) {
  V[cnt].push_back(-n);
  bel[n] = cnt;
  for (int e = first[n]; e; e = nxt[e])
    if (vv[e] - fa[n]) fa[vv[e]] = n, dfs2(vv[e]);
}
void gao(int n) {
  ++cnt;
  V[cnt].push_back(-10000000);
  dfs2(n);
  sort(V[cnt].begin(), V[cnt].end());
  for (int i = 0; i < V[cnt].size(); i++) V[cnt][i] *= -1;
  top[cnt] = V[cnt][V[cnt].size() - 1];
  sum[cnt] = V[cnt].size() * 2 - 2;
}
int ans[maxn];
int w[maxn];
int main() {
  int n, i, j, k;
  int u, v, e = 2;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d%d%d", &u, &v, &j);
    nxt[e] = first[u], vv[e] = v, w[e] = j, first[u] = e++;
    nxt[e] = first[v], vv[e] = u, w[e] = j, first[v] = e++;
  }
  if (n == 1) {
    puts("0\n1");
    return 0;
  } else if (n == 2) {
    printf("%d\n2 1\n", w[2] * 2);
    return 0;
  }
  int root = getRoot(n);
  memset(fa, 0, sizeof(fa));
  dfs1(root);
  long long ans1 = 0;
  for (i = 2; i < e; i++)
    if (fa[vv[i]] == (vv[i ^ 1]))
      ans1 += (w[i] + 0ll) * min(siz[vv[i]], n - siz[vv[i]]) * 2;
  for (i = first[root]; i; i = nxt[i]) gao(vv[i]);
  ++cnt;
  V[cnt].push_back(1000000);
  V[cnt].push_back(root);
  top[cnt] = root;
  sum[cnt] = 2;
  bel[root] = cnt;
  build(1, 1, cnt);
  int cur = n;
  int l, r;
  for (i = 1; i <= n; i++) {
    int r = bel[i];
    int m;
    if (r == 1) {
      m = get_sum(1, r + 1, cnt);
      if (sum[m] - cur || m == bel[root]) m = get_top(1, r + 1, cnt);
    } else if (r == cnt) {
      m = get_sum(1, 1, r - 1);
      if (sum[m] - cur || m == bel[root]) m = get_top(1, 1, r - 1);
    } else {
      int m1 = get_sum(1, 1, r - 1);
      int m2 = get_sum(1, r + 1, cnt);
      m = sum[m1] > sum[m2] ? m1 : m2;
      if (sum[m] - cur || m == bel[root]) {
        m1 = get_top(1, 1, r - 1);
        m2 = get_top(1, r + 1, cnt);
        m = top[m1] < top[m2] ? m1 : m2;
      }
    }
    if (i == root && sum[m] - cur) {
      if (top[m] > i) m = r;
    }
    upd_sum(1, m, sum[m] - 1);
    upd_sum(1, r, sum[r] - 1);
    ans[i] = top[m];
    upd_top(1, m);
    cur--;
  }
  cout << ans1 << endl;
  for (i = 1; i <= n; i++) printf("%d ", ans[i]);
  puts("");
}
