#include <bits/stdc++.h>
using namespace std;
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const int MAXN = 1e5 + 10;
int n, sz[MAXN], col[MAXN];
vector<pair<int, int>> c[MAXN];
long long ans;
set<pair<int, int>> curr, bad;
set<int> val[MAXN];
int dsz(int v = 0, int pr = -1) {
  sz[v] = 1;
  for (const auto& [to, cost] : c[v])
    if (to != pr) sz[v] += dsz(to, v);
  return sz[v];
}
int find_centroid() {
  dsz();
  int v = 0, pr = -1;
  bool good = 1;
  while (good) {
    good = 0;
    for (const auto& [to, cost] : c[v])
      if (to != pr && sz[to] > n / 2) {
        pr = v;
        v = to;
        good = 1;
        break;
      }
  }
  return v;
}
void dfs(int v, int co, int pr = -1, long long d = 0) {
  col[v] = co;
  val[co].insert(v);
  ans += 2 * d;
  for (const auto& [to, cost] : c[v])
    if (to != pr) dfs(to, co, v, d + cost);
}
int main() {
  faster();
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    c[u].push_back({v, w});
    c[v].push_back({u, w});
  }
  int s = find_centroid();
  col[s] = 0;
  val[0].insert(s);
  int cnt = 1;
  for (const auto& [to, cost] : c[s]) dfs(to, cnt++, s, cost);
  cout << ans << '\n';
  for (int i = 0; i < n; ++i) sz[i] = 0;
  for (int i = 0; i < cnt; i++) {
    curr.insert({*val[i].begin(), i});
    if (i) bad.insert({2 * val[i].size(), i});
    sz[i] = val[i].size();
  }
  int sum = n;
  for (int i = 0; i < n; i++) {
    auto it = curr.begin();
    while ((col[i] && it->second == col[i]) && it != curr.end()) it++;
    if (bad.size()) {
      auto p = *bad.rbegin();
      if (col[i] != p.second) {
        int x = sum;
        if (it->second != p.second) x--;
        if (p.first > x) it = curr.find({*val[p.second].begin(), p.second});
      }
      sum--;
      bad.erase({sz[col[i]] + val[col[i]].size(), col[i]});
      sz[col[i]]--;
      if (col[i] != 0) bad.insert({sz[col[i]] + val[col[i]].size(), col[i]});
    }
    cout << it->first + 1 << ' ';
    int x = it->second;
    bad.erase({sz[x] + val[x].size(), x});
    val[x].erase(it->first);
    if (x != 0) bad.insert({sz[x] + val[x].size(), x});
    curr.erase(it);
    if (val[x].size()) curr.insert({*val[x].begin(), x});
  }
}
