#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <typename T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
  gn(first);
  gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
  gn(first);
  gn(second);
  gn(z);
}
template <typename T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <typename T>
inline void println(T first) {
  print(first), putchar('\n');
}
template <typename T>
inline void printsp(T first) {
  print(first), putchar(' ');
}
template <class T, class T1>
inline void print(T first, T1 second) {
  printsp(first), println(second);
}
template <class T, class T1, class T2>
inline void print(T first, T1 second, T2 z) {
  printsp(first), printsp(second), println(z);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
vector<pair<int, int> > adj[200100];
int n, A;
int sz[200100], mx[200100];
void dfs(int u, int fa = 0) {
  sz[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i].first;
    if (v == fa) continue;
    dfs(v, u);
    sz[u] += sz[v];
    smax(mx[u], sz[v]);
  }
  smax(mx[u], n - sz[u]);
  if (mx[u] <= n / 2) A = u;
}
int id[200100];
set<int> s[200100];
long long ans;
void dfs(int u, int fa, long long dep, int k) {
  id[u] = k;
  s[k].insert(u);
  ans += dep;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i].first;
    if (v == fa) continue;
    dfs(v, u, dep + adj[u][i].second, k);
  }
}
int cnt[200100];
int p[200100];
set<pair<int, int> > ss;
set<int> mn;
void solve(int u) {
  id[u] = 0;
  s[0].insert(u);
  int k = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i].first;
    dfs(v, u, adj[u][i].second, k);
    k++;
  }
  for (int i = 0; i < k; i++) {
    ss.insert(pair<int, int>(cnt[i] = (s[i].size() << 1), i));
    mn.insert(*s[i].begin());
  }
  for (int i = 1; i < n; i++) {
    int u = id[i], v, val;
    ss.erase(pair<int, int>(cnt[u], u));
    ss.insert(pair<int, int>(--cnt[u], u));
    if (ss.rbegin()->first == n - i + 1) {
      v = ss.rbegin()->second;
      if (v == 0)
        val = *mn.begin();
      else
        val = *s[v].begin();
    } else {
      for (set<int>::iterator it = mn.begin();; it++) {
        val = *it;
        v = id[val];
        if (v == 0 || u != v) break;
      }
    }
    s[v].erase(val);
    mn.erase(val);
    p[i] = val;
    if (!s[v].empty()) mn.insert(*s[v].begin());
    ss.erase(pair<int, int>(cnt[v], v));
    ss.insert(pair<int, int>(--cnt[v], v));
  }
  p[n] = *mn.begin();
}
int main() {
  gn(n);
  for (int i = 1; i < n; i++) {
    int u, v, w;
    gn(u, v, w);
    adj[u].push_back(pair<int, int>(v, w));
    adj[v].push_back(pair<int, int>(u, w));
  }
  dfs(1);
  solve(A);
  println(ans << 1);
  for (int i = 1; i <= n; i++) printsp(p[i]);
  puts("");
  return 0;
}
