#include <bits/stdc++.h>
using namespace std;
int n, cnt, x, y, z, tot;
int sub[100005], p[100005], l[100005], r[100005], gr[100005];
long long der[100005];
long long ans;
vector<int> val[100005];
vector<pair<int, int> > v[100005];
multiset<pair<int, int> > s, s2;
void dfs2(int node, int ata) {
  sub[node] = 1;
  ans += der[node] * 2;
  gr[node] = tot;
  val[tot].push_back(node);
  for (pair<int, int> i : v[node]) {
    if (i.first == ata) continue;
    der[i.first] = der[node] + i.second;
    dfs2(i.first, node);
    sub[node] += sub[i.first];
  }
}
void dfs1(int node, int ata) {
  sub[node] = 1;
  bool iscnt = true;
  for (pair<int, int> i : v[node]) {
    if (i.first == ata) continue;
    dfs1(i.first, node);
    iscnt &= (sub[i.first] <= n / 2);
    sub[node] += sub[i.first];
  }
  iscnt &= (n - sub[node] <= n / 2);
  if (iscnt) cnt = node;
}
void clear(int g, bool ty) {
  if (!ty) {
    s.erase(s.find({l[g] + r[g], g}));
    l[g]--;
    if (l[g] + r[g]) s.insert({l[g] + r[g], g});
  } else {
    s.erase(s.find({l[g] + r[g], g}));
    s2.erase(s2.find({val[g].back(), g}));
    r[g]--;
    val[g].pop_back();
    if (l[g] + r[g]) s.insert({l[g] + r[g], g});
    if (r[g]) s2.insert({val[g].back(), g});
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d %d %d", &x, &y, &z);
    v[x].push_back({y, z});
    v[y].push_back({x, z});
  }
  dfs1(1, 0);
  for (pair<int, int> i : v[cnt]) {
    ++tot;
    der[i.first] = i.second;
    dfs2(i.first, cnt);
    sort(val[tot].begin(), val[tot].end(), greater<int>());
    l[tot] = r[tot] = sub[i.first];
    s.insert({l[tot] + r[tot], tot});
    s2.insert({val[tot].back(), tot});
  }
  val[0].push_back(cnt);
  l[0] = r[0] = 1;
  s.insert({2, 0});
  s2.insert({val[0][0], 0});
  printf("%lld\n", ans);
  for (int i = 1; i <= n; i++) {
    if (s.rbegin()->second != 0 && s.rbegin()->second != gr[i] &&
        s.rbegin()->first == n - i + 1) {
      p[i] = val[s.rbegin()->second].back();
      clear(gr[i], 0);
      clear(gr[p[i]], 1);
    } else {
      for (auto x : s2) {
        if (x.second == gr[i] && i != cnt) continue;
        p[i] = val[x.second].back();
        int tut = x.second;
        clear(gr[i], 0);
        clear(tut, 1);
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++) printf("%d ", p[i]);
}
