#include <bits/stdc++.h>
using namespace std;
int n, d[100010], tail, zx, zxcnt, sz[100010], zhx[100010];
int lxx[100010];
int aa[100010], bb[100010], ttl[100010];
vector<int> v[100010];
long long jgg;
struct bbbb {
  int ne, to;
  long long xx;
} b[200010];
void jb(int x, int y, long long z) {
  tail++;
  b[tail].ne = d[x];
  b[tail].to = y;
  b[tail].xx = z;
  d[x] = tail;
  return;
}
void dfszx(int x, int ff) {
  sz[x] = 1;
  int mxsz = 0;
  for (int i = d[x]; i; i = b[i].ne) {
    int y = b[i].to;
    if (y == ff) continue;
    dfszx(y, x);
    sz[x] += sz[y];
    mxsz = max(mxsz, sz[y]);
  }
  for (int i = d[x]; i; i = b[i].ne) {
    int y = b[i].to;
    if (y == ff) continue;
    jgg += min(sz[y], n - sz[y]) * 2 * b[i].xx;
  }
  if (max(mxsz, n - sz[x]) <= n / 2) {
    zhx[x] = 1;
    zxcnt++;
    zx = x;
  }
  return;
}
void dfs1(int x, int ff, int lx) {
  v[lx].push_back(x);
  lxx[x] = lx;
  aa[lx]++;
  bb[lx]++;
  for (int i = d[x]; i; i = b[i].ne) {
    int y = b[i].to;
    if (y == ff || zhx[y] == 1) continue;
    dfs1(y, x, lx);
  }
  return;
}
priority_queue<pair<int, int> > q, qq;
void pppp() {
  while (!q.empty()) {
    int x = q.top().first, y = q.top().second;
    if (x != aa[y] + bb[y] || aa[y] == 0) {
      q.pop();
    } else
      break;
  }
  return;
}
void ppppp() {
  while (!qq.empty()) {
    int x = -qq.top().first, y = qq.top().second;
    if (ttl[y] >= v[y].size() || v[y][ttl[y]] != x) {
      qq.pop();
    } else
      break;
  }
}
int xuan(int xx) {
  ppppp();
  if (qq.top().second == xx && xx != 0) {
    int x = qq.top().first, y = qq.top().second;
    qq.pop();
    ppppp();
    int x_ = -qq.top().first, y_ = qq.top().second;
    qq.pop();
    aa[y_]--;
    ttl[y_]++;
    q.push(make_pair(aa[y_] + bb[y_], y_));
    qq.push(make_pair(-v[y_][ttl[y_]], y_));
    qq.push(make_pair(x, y));
    return x_;
  }
  int x_ = -qq.top().first, y_ = qq.top().second;
  qq.pop();
  aa[y_]--;
  ttl[y_]++;
  q.push(make_pair(aa[y_] + bb[y_], y_));
  qq.push(make_pair(-v[y_][ttl[y_]], y_));
  return x_;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    long long z;
    scanf("%d%d%lld", &x, &y, &z);
    jb(x, y, z);
    jb(y, x, z);
  }
  dfszx(1, 0);
  printf("%lld\n", jgg);
  if (zxcnt > 1) {
    int ee = -1;
    for (int i = 1; i <= n; i++) {
      if (zhx[i] == 1) {
        ee++;
        dfs1(i, 0, ee);
      }
    }
    sort(v[0].begin(), v[0].end());
    sort(v[1].begin(), v[1].end());
    for (int i = 1; i <= n; i++) {
      printf("%d ", v[lxx[i] ^ 1][ttl[lxx[i] ^ 1]]);
      ttl[lxx[i] ^ 1]++;
    }
    return 0;
  }
  int lxlx = 0, nn = n;
  v[0].push_back(zx);
  q.push(make_pair(2, 0));
  aa[0] = bb[0] = 1;
  qq.push(make_pair(-zx, 0));
  for (int i = d[zx]; i; i = b[i].ne) {
    int y = b[i].to;
    lxlx++;
    dfs1(y, zx, lxlx);
    q.push(make_pair(aa[lxlx] + bb[lxlx], lxlx));
    sort(v[lxlx].begin(), v[lxlx].end());
    qq.push(make_pair(-v[lxlx][0], lxlx));
  }
  for (int i = 1; i <= n; i++) {
    pppp();
    if (nn == q.top().first && lxx[i] != q.top().second &&
        q.top().second != 0) {
      int qw = q.top().second;
      q.pop();
      printf("%d ", v[qw][ttl[qw]]);
      aa[qw]--;
      ttl[qw]++;
      q.push(make_pair(aa[qw] + bb[qw], qw));
      qq.push(make_pair(-v[qw][ttl[qw]], qw));
    } else {
      int awa = xuan(lxx[i]);
      printf("%d ", awa);
    }
    bb[lxx[i]]--;
    q.push(make_pair(aa[lxx[i]] + bb[lxx[i]], lxx[i]));
    nn--;
  }
  return 0;
}
