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;
inline int read() {
  int f = 1, ans = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  return f * ans;
}
const int MAXN = 1e5 + 11;
int N, siz[MAXN], rt, Minn = INT_MAX;
vector<pair<int, int> > vec[MAXN];
long long res;
void dfs(int u, int fath) {
  siz[u] = 1;
  int Max = 0;
  for (auto pp : vec[u]) {
    int v = pp.first, w = pp.second;
    if (v == fath) continue;
    dfs(v, u);
    siz[u] += siz[v];
    Max = max(Max, siz[v]);
    res += (long long)min(siz[v], N - siz[v]) * w;
  }
  Max = max(Max, N - siz[u]);
  if (Max < Minn) {
    rt = u;
    Minn = Max;
  }
  return;
}
int col[MAXN], cnt, Ans[MAXN];
set<int> s[MAXN];
void dfs1(int u, int fath, int co) {
  col[u] = co;
  for (auto pp : vec[u])
    if (pp.first != fath) dfs1(pp.first, u, co);
}
struct Segment1 {
  int Minn[MAXN << 2];
  void Modify(int k, int l, int r, int ps, int w) {
    if (l == r) {
      Minn[k] = w;
      return;
    }
    int mid = (l + r) >> 1;
    if (ps <= mid)
      Modify(k << 1, l, mid, ps, w);
    else
      Modify(k << 1 | 1, mid + 1, r, ps, w);
    Minn[k] = min(Minn[k << 1], Minn[k << 1 | 1]);
    return;
  }
  int Query(int k, int l, int r, int x, int y) {
    if (x > y) return INT_MAX;
    if (x <= l && r <= y) return Minn[k];
    int res = INT_MAX, mid = (l + r) >> 1;
    if (x <= mid) res = min(res, Query(k << 1, l, mid, x, y));
    if (mid < y) res = min(res, Query(k << 1 | 1, mid + 1, r, x, y));
    return res;
  }
} S1;
struct Segment2 {
  int Minn[MAXN << 2], tag[MAXN << 2];
  void pushdown(int k) {
    if (!tag[k]) return;
    tag[k << 1] += tag[k], tag[k << 1 | 1] += tag[k];
    Minn[k << 1] += tag[k], Minn[k << 1 | 1] += tag[k];
    tag[k] = 0;
    return;
  }
  void build(int k, int l, int r) {
    if (l == r) {
      Minn[k] = (N - s[l].size()) - s[l].size();
      return;
    }
    int mid = (l + r) >> 1;
    build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);
    Minn[k] = min(Minn[k << 1], Minn[k << 1 | 1]);
    return;
  }
  void Add(int k, int l, int r, int x, int y, int w) {
    if (x > y) return;
    if (x <= l && r <= y) {
      tag[k] += w, Minn[k] += w;
      return;
    }
    pushdown(k);
    int mid = (l + r) >> 1;
    if (x <= mid) Add(k << 1, l, mid, x, y, w);
    if (mid < y) Add(k << 1 | 1, mid + 1, r, x, y, w);
    Minn[k] = min(Minn[k << 1], Minn[k << 1 | 1]);
    return;
  }
  int Query(int k, int l, int r, int x, int y) {
    if (x <= l && r <= y) return Minn[k];
    pushdown(k);
    int mid = (l + r) >> 1, res = INT_MAX;
    if (x <= mid) res = min(res, Query(k << 1, l, mid, x, y));
    if (mid < y) res = min(res, Query(k << 1 | 1, mid + 1, r, x, y));
    Minn[k] = min(Minn[k << 1], Minn[k << 1 | 1]);
    return res;
  }
  int Qpos(int k, int l, int r) {
    if (l == r) return l;
    pushdown(k);
    int mid = (l + r) >> 1, ps;
    if (Minn[k << 1] < Minn[k << 1 | 1])
      ps = Qpos(k << 1, l, mid);
    else
      ps = Qpos(k << 1 | 1, mid + 1, r);
    Minn[k] = min(Minn[k << 1], Minn[k << 1 | 1]);
    return ps;
  }
} S2;
int Vis[MAXN], vis[MAXN], tmp1[MAXN], tmp2[MAXN], NumR[MAXN], Num[MAXN];
int Ans1[MAXN], Ans2[MAXN];
void calc() {
  int ps;
  while (1) {
    int w = S2.Minn[1];
    if (w) return;
    ps = S2.Qpos(1, 1, cnt);
    if (Num[ps] == NumR[ps]) {
      S2.Add(1, 1, cnt, ps, ps, INT_MAX / 3);
      continue;
    }
    break;
  }
  tmp1[0] = tmp2[0] = 0;
  int p1, q1, p2, q2;
  for (int i = 1; i <= N; i++) {
    if (Vis[i]) continue;
    if (col[i] == ps) tmp1[++tmp1[0]] = i;
  }
  for (int i = 1; i <= N; i++) {
    if (vis[i]) continue;
    if (col[i] != ps) tmp2[++tmp2[0]] = i;
  }
  p1 = tmp1[1], q1 = tmp2[1];
  if (tmp1[0] == 1) {
    Ans[p1] = q1;
    Vis[p1] = vis[q1] = 1;
    for (int i = 1; i <= N; i++) {
      if (!Vis[i]) p2 = i;
      if (!vis[i]) q2 = i;
    }
    Ans[p2] = q2;
    if (p1 != rt && q1 != rt || (p1 == q2 && p2 == q1)) {
      for (int i = 1; i <= N; i++) printf("%d ", Ans[i]);
      printf("\n");
      exit(0);
    }
    for (int i = 1; i <= N; i++) Ans1[i] = Ans[i];
    swap(Ans[p1], Ans[p2]);
    for (int i = 1; i <= N; i++) Ans2[i] = Ans[i];
    int ff = -1;
    for (int i = 1; i <= N; i++) {
      if (Ans1[i] < Ans2[i]) {
        ff = 1;
        break;
      } else if (Ans1[i] > Ans2[i]) {
        ff = 0;
        break;
      }
    }
    if (ff) {
      for (int i = 1; i <= N; i++) printf("%d ", Ans1[i]);
      printf("\n");
      exit(0);
    }
    for (int i = 1; i <= N; i++) printf("%d ", Ans2[i]);
    printf("\n");
    exit(0);
  }
  for (int i = 1; i <= tmp1[0]; i++)
    Ans[tmp1[i]] = tmp2[i], Vis[tmp1[i]] = 1, vis[tmp2[i]] = 1;
  tmp1[0] = tmp2[0] = 0;
  for (int i = 1; i <= N; i++) {
    if (!Vis[i]) tmp1[++tmp1[0]] = i;
    if (!vis[i]) tmp2[++tmp2[0]] = i;
  }
  for (int i = 1; i <= tmp1[0]; i++)
    Ans[tmp1[i]] = tmp2[i], Vis[tmp1[i]] = 1, vis[tmp2[i]] = 1;
  for (int i = 1; i <= N; i++) printf("%d ", Ans[i]);
  printf("\n");
  exit(0);
}
void confirm(int u, int v) {
  Ans[u] = v;
  Vis[u] = vis[v] = 1;
  Num[col[u]]++;
  s[col[v]].erase(v);
  if (s[col[v]].size())
    S1.Modify(1, 1, cnt, col[v], *s[col[v]].begin());
  else
    S1.Modify(1, 1, cnt, col[v], INT_MAX);
  S2.Add(1, 1, cnt, 1, col[u] - 1, -1), S2.Add(1, 1, cnt, col[u] + 1, cnt, -1),
      S2.Add(1, 1, cnt, col[v], col[v], 1);
}
int main() {
  N = read();
  for (int i = 1; i < N; i++) {
    int u = read(), v = read(), w = read();
    vec[u].push_back(make_pair(v, w)), vec[v].push_back(make_pair(u, w));
  }
  dfs(1, 0);
  for (auto pp : vec[rt]) dfs1(pp.first, rt, ++cnt);
  col[rt] = ++cnt;
  printf("%lld\n", res * 2);
  for (int i = 1; i <= N; i++) s[col[i]].insert(i), NumR[col[i]]++;
  for (int i = 1; i <= cnt; i++) S1.Modify(1, 1, cnt, i, *s[i].begin());
  S2.build(1, 1, cnt);
  for (int i = 1; i <= N; i++) {
    if (Vis[i]) continue;
    calc();
    int W = min(S1.Query(1, 1, cnt, 1, col[i] - 1),
                S1.Query(1, 1, cnt, col[i] + 1, cnt));
    if (i == rt && i < W) W = i;
    confirm(i, W);
  }
  for (int i = 1; i <= N; i++) printf("%d ", Ans[i]);
  printf("\n");
  return 0;
}
