Little X has a tree consisting of n nodes (they are numbered from 1 to n). Each edge of the tree has a positive length. Let's define the distance between two nodes v and u (we'll denote it d(v, u)) as the sum of the lengths of edges in the shortest path between v and u. 

A permutation p is a sequence of n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n). Little X wants to find a permutation p such that sum <image> is maximal possible. If there are multiple optimal permutations, he wants to find the lexicographically smallest one. Help him with the task!

Input

The first line contains an integer n (1 ≤ n ≤ 105).

Each of the next n - 1 lines contains three space separated integers ui, vi, wi (1 ≤ ui, vi ≤ n; 1 ≤ wi ≤ 105), denoting an edge between nodes ui and vi with length equal to wi.

It is guaranteed that these edges form a tree.

Output

In the first line print the maximum possible value of the described sum. In the second line print n integers, representing the lexicographically smallest permutation.

Examples

Input

2
1 2 3


Output

6
2 1


Input

5
1 2 2
1 3 3
2 4 4
2 5 5


Output

32
2 1 4 5 3
#include <bits/stdc++.h>
using namespace std;
void getre() {
  int x = 0;
  printf("%d\n", 1 / x);
}
void gettle() {
  int res = 1;
  while (1) res <<= 1;
  printf("%d\n", res);
}
template <typename T, typename S>
inline bool upmin(T &a, const S &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool upmax(T &a, const S &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename N, typename PN>
inline N flo(N a, PN b) {
  return a >= 0 ? a / b : -((-a - 1) / b) - 1;
}
template <typename N, typename PN>
inline N cei(N a, PN b) {
  return a > 0 ? (a - 1) / b + 1 : -(-a / b);
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
template <typename N>
inline int sgn(N a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
inline void gn(long long &x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gn(long double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gs(char *s) { scanf("%s", s); }
inline void gc(char &c) {
  while ((c = getchar()) > 126 || c < 33)
    ;
}
inline void pc(char c) { putchar(c); }
inline long long sqr(long long a) { return a * a; }
inline double sqrf(double a) { return a * a; }
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846264338327950288L;
const double eps = 1e-6;
const int mo = 1;
int qp(int a, long long b) {
  int n = 1;
  do {
    if (b & 1) n = 1ll * n * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return n;
}
const int TREE_MAXV = 100000 + 5;
struct edge {
  int v, w, next;
} e[TREE_MAXV * 2];
int g[TREE_MAXV], etot;
int qu[TREE_MAXV], pre[TREE_MAXV], sz[TREE_MAXV], ma[TREE_MAXV], bel[TREE_MAXV];
long long h[TREE_MAXV];
int tot;
int n;
void ae(int u, int v, int w) {
  e[etot].v = v;
  e[etot].w = w;
  e[etot].next = g[u];
  g[u] = etot++;
}
void bfs(int rt) {
  tot = 0;
  int p = 0, q = 0;
  pre[rt] = 0;
  qu[q++] = rt;
  h[rt] = 0;
  bel[rt] = 0;
  while (p != q) {
    int u = qu[p++];
    sz[u] = 1;
    for (int i = g[u]; ~i; i = e[i].next)
      if (e[i].v != pre[u]) {
        pre[e[i].v] = u;
        h[e[i].v] = h[u] + e[i].w;
        qu[q++] = e[i].v;
        if (bel[u] == 0)
          bel[e[i].v] = ++tot;
        else
          bel[e[i].v] = bel[u];
      }
  }
  bel[rt] = ++tot;
  for (int i = (q)-1, _ed = (1); i >= _ed; i--) sz[pre[qu[i]]] += sz[qu[i]];
  for (int u = (1), _ed = (n + 1); u < _ed; u++) {
    ma[u] = n - sz[u];
    for (int i = g[u]; ~i; i = e[i].next)
      if (e[i].v != pre[u]) upmax(ma[u], sz[e[i].v]);
  }
}
void tree_init() {
  static bool ini = 0;
  if (!ini) {
    ini = 1;
    memset(g, -1, sizeof(g));
  } else {
    for (int i = 0; i <= n; i++) g[i] = -1;
  }
  etot = 0;
}
void readedge() {
  for (int i = 1; i < n; i++) {
    int x, y, w;
    gn(x);
    gn(y);
    gn(w);
    ae(x, y, w);
    ae(y, x, w);
  }
}
vector<int> cen;
int ou[111111];
int ans[111111];
void upans() {
  for (int i = 1; i <= n; i++)
    if (ans[i] != ou[i]) {
      if (ans[i] > ou[i])
        return;
      else {
        for (int j = (1), _ed = (n + 1); j < _ed; j++) ou[j] = ans[j];
        return;
      }
    }
}
int cnt[111111];
set<int> second[111111];
set<int> big;
int curdel;
set<int> zer;
set<pair<int, int> > du;
void link(int x, int y) {
  int bx = bel[x], by = bel[y];
  assert(bx != by);
  ans[x] = y;
  big.erase(y);
  second[by].erase(y);
  if (!second[by].empty()) big.insert(*second[by].begin());
  du.erase(make_pair(cnt[bx], bx));
  du.erase(make_pair(cnt[by], by));
  cnt[bx]++;
  cnt[by]++;
  curdel++;
  du.insert(make_pair(cnt[bx], bx));
  du.insert(make_pair(cnt[by], by));
  for (__typeof((du).begin()) it = (du).begin(); it != (du).end(); it++) {
    if (it->first != curdel) break;
    if (zer.find(it->second) != zer.end()) continue;
    zer.insert(it->second);
  }
}
void work() {
  ans[1] = inf;
  if (n == 0) return;
  if (tot <= 1) return;
  memset((cnt), (0), sizeof(cnt));
  for (int i = (1), _ed = (n + 1); i < _ed; i++) second[i].clear();
  for (int i = (1), _ed = (n + 1); i < _ed; i++) {
    cnt[bel[i]]++;
    second[bel[i]].insert(i);
  }
  curdel = 0;
  zer.clear();
  du.clear();
  for (int i = (1), _ed = (tot + 1); i < _ed; i++) {
    cnt[i] = n - cnt[i] - cnt[i];
    if (cnt[i] == 0) zer.insert(i);
    du.insert(make_pair(cnt[i], i));
  }
  for (int i = (1), _ed = (tot + 1); i < _ed; i++)
    big.insert(*second[i].begin());
  for (int i = (1), _ed = (n + 1); i < _ed; i++) {
    int b = bel[i];
    int to;
    if (((int)(zer).size()) > (curdel == cnt[b])) {
      for (__typeof((zer).begin()) it = (zer).begin(); it != (zer).end(); it++)
        if (*it != b) {
          to = *it;
          break;
        }
    } else {
      int x;
      for (__typeof((big).begin()) it = (big).begin(); it != (big).end();
           it++) {
        if (bel[*it] != b) {
          x = *it;
          break;
        }
      }
      to = bel[x];
    }
    int ya = *second[to].begin();
    link(i, ya);
  }
}
int main() {
  gn(n);
  tree_init();
  readedge();
  bfs(1);
  for (int i = (1), _ed = (n + 1); i < _ed; i++)
    if (ma[i] * 2 <= n) cen.push_back(i);
  bfs(cen[0]);
  long long su = 0;
  for (int i = (1), _ed = (n + 1); i < _ed; i++) su += h[i];
  su <<= 1;
  cout << su << endl;
  ou[1] = n + 1;
  for (int i = (0), _ed = (((int)(cen).size())); i < _ed; i++) {
    bfs(cen[i]);
    work();
    upans();
    int x = cen[i];
    if (ma[x] * 2 < n) {
      for (int j = x + 1; j <= n; j++) bel[j - 1] = bel[j];
      tot--;
      n--;
      work();
      n++;
      for (int j = n; j >= x + 1; j--) ans[j] = ans[j - 1];
      for (int i = (1), _ed = (n + 1); i < _ed; i++)
        if (ans[i] >= x) ans[i]++;
      ans[x] = x;
      upans();
    }
  }
  for (int i = (1), _ed = (n + 1); i < _ed; i++) printf("%d ", ou[i]);
  return 0;
}
