#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 20;
long long N, M, root, sze[maxn], gr[maxn], ab[maxn], ans[maxn], mx;
vector<pair<long long, long long> > komsu[maxn];
set<pair<long long, long long> > abss, mns;
set<long long> st[maxn];
void dfs(long long node, long long dad) {
  sze[node] = 1;
  for (long long i = 0; i < komsu[node].size(); i++) {
    long long x = komsu[node][i].first;
    if (x == dad) continue;
    dfs(x, node);
    sze[node] += sze[x];
  }
}
long long find_cen() {
  long long node = 1;
  bool flag = 1;
  while (flag) {
    flag = 0;
    for (long long i = 0; i < komsu[node].size(); i++) {
      long long x = komsu[node][i].first;
      if (sze[x] > sze[node]) continue;
      if (sze[x] * 2 > N) {
        flag = 1;
        node = x;
        break;
      }
    }
  }
  return node;
}
void dfss(long long node, long long dad, long long mes, long long part) {
  gr[node] = part;
  ab[part] += 2;
  st[part].insert(node);
  mx += 2 * mes;
  for (long long i = 0; i < komsu[node].size(); i++) {
    pair<long long, long long> x = komsu[node][i];
    if (x.first == dad) continue;
    dfss(x.first, node, mes + x.second, part);
  }
}
void change_ab(long long part) {
  abss.erase(abss.find(pair<long long, long long>(ab[part], part)));
  abss.insert(pair<long long, long long>(--ab[part], part));
}
void take(long long part, long long i) {
  ans[i] = *st[part].begin();
  mns.erase(mns.find(pair<long long, long long>(*st[part].begin(), part)));
  st[part].erase(st[part].begin());
  change_ab(part);
  if (st[part].size())
    mns.insert(pair<long long, long long>(*st[part].begin(), part));
}
void solve() {
  for (long long i = 1; i <= M; i++) {
    mns.insert(pair<long long, long long>(*st[i].begin(), i));
    abss.insert(pair<long long, long long>(ab[i], i));
  }
  for (long long i = 1; i <= N; i++) {
    change_ab(gr[i]);
    pair<long long, long long> x = *abss.rbegin();
    if (x.first == N - i + 1)
      take(x.second, i);
    else {
      __typeof(mns.begin()) it = mns.begin();
      if (gr[i] != 1 && (*it).second == gr[i]) it++;
      take((*it).second, i);
    }
  }
}
int main() {
  cin >> N;
  for (long long i = 1; i < N; i++) {
    long long a, b, c;
    scanf("%lld %lld %lld", &a, &b, &c);
    komsu[a].push_back(pair<long long, long long>(b, c));
    komsu[b].push_back(pair<long long, long long>(a, c));
  }
  dfs(1, 0);
  root = find_cen();
  gr[root] = ++M, sze[1] = 1, st[1].insert(root);
  for (long long i = 0; i < komsu[root].size(); i++)
    dfss(komsu[root][i].first, root, komsu[root][i].second, ++M);
  solve();
  cout << mx << endl;
  for (long long i = 1; i <= N; i++) printf("%lld ", ans[i]);
  puts("");
  return 0;
}
