Problem: This problem is split into two tasks. In this task, you are required to find the minimum possible answer. In the task Village (Maximum) you are required to find the maximum possible answer. Each task is worth 50 points.

There are N houses in a certain village. A single villager lives in each of the houses. The houses are connected by roads. Each road connects two houses and is exactly 1 kilometer long. From each house it is possible to reach any other using one or several consecutive roads. In total there are N-1 roads in the village.

One day all villagers decided to move to different houses — that is, after moving each house should again have a single villager living in it, but no villager should be living in the same house as before. We would like to know the smallest possible total length in kilometers of the shortest paths between the old and the new houses for all villagers.

<image>

Example village with seven houses 

For example, if there are seven houses connected by roads as shown on the figure, the smallest total length is 8 km (this can be achieved by moving 1 → 6, 2 → 4, 3 → 1, 4 → 2, 5 → 7, 6 → 3, 7 → 5).

Write a program that finds the smallest total length of the shortest paths in kilometers and an example assignment of the new houses to the villagers.

Input

The first line contains an integer N (1 < N ≤ 10^5). Houses are numbered by consecutive integers 1, 2, …, N.

Then N-1 lines follow that describe the roads. Each line contains two integers a and b (1 ≤ a, b ≤ N, a ≠ b) denoting that there is a road connecting houses a and b.

Output

In the first line output the smallest total length of the shortest paths in kilometers.

In the second line describe one valid assignment of the new houses with the smallest total length: N space-separated distinct integers v_1, v_2, …, v_N. For each i, v_i is the house number where the villager from the house i should move (v_i ≠ i). If there are several valid assignments, output any of those.

Scoring

Subtasks: 

  1. (6 points) N ≤ 10 
  2. (19 points) N ≤ 1 000 
  3. (25 points) No further constraints 

Examples

Input


4
1 2
2 3
3 4


Output


4
2 1 4 3


Input


7
4 2
5 7
3 4
6 3
1 3
4 5


Output


8
3 4 6 2 7 1 5

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct BigNum {
  vector<long long> value;
  void set(long long x) {
    value = *(new vector<long long>);
    value.push_back(x);
  }
  void duplicate(BigNum other) { value = other.value; }
  void add(BigNum other) {
    vector<long long> o = other.value;
    if (o.size() > value.size()) {
      vector<long long> t = value;
      value = o;
      o = t;
    }
    for (int i = 0; i < o.size(); i += 1) {
      value[i] += o[i];
      if (i < value.size() - 1 && value[i] >= (long long)1e9) {
        value[i + 1] += value[i] / (long long)1e9;
        value[i] = value[i] % (long long)1e9;
      }
    }
    if (value.back() >= (long long)1e9) {
      value.push_back(value.back() / (long long)1e9);
      value[value.size() - 2] = value[value.size() - 2] % (long long)1e9;
    }
  }
  void mul(long long mul) {
    for (int i = 0; i < value.size(); i += 1) {
      value[i] *= mul;
    }
    for (int i = 0; i < value.size() - 1; i += 1) {
      if (value[i] >= (long long)1e9) {
        value[i + 1] += value[i] / (long long)1e9;
        value[i] = value[i] % (long long)1e9;
      }
    }
    if (value.back() >= (long long)1e9) {
      value.push_back(value.back() / (long long)1e9);
      value[value.size() - 2] = value[value.size() - 2] % (long long)1e9;
    }
  }
  long double div(BigNum other1, BigNum other2) {
    int s = value.size();
    long double current = value.back();
    if (s >= 2) {
      current += ((long double)value[s - 2]) / (long long)1e9;
    }
    if (s >= 3) {
      current +=
          ((long double)value[s - 3]) / ((long long)1e9 * (long long)1e9);
    }
    int s1 = other1.value.size();
    int s2 = other2.value.size();
    long double other = 0;
    if (s1 + s2 - 1 == s) {
      other += other1.value.back() * other2.value.back();
      if (s1 >= 2) {
        other += ((long double)other1.value[s1 - 2] * other2.value.back()) /
                 (long long)1e9;
      }
      if (s2 >= 2) {
        other += ((long double)other2.value[s2 - 2] * other1.value.back()) /
                 (long long)1e9;
      }
      if (s1 >= 3) {
        other += ((long double)other1.value[s1 - 3] * other2.value.back()) /
                 ((long long)1e9 * (long long)1e9);
      }
      if (s2 >= 3) {
        other += ((long double)other2.value[s2 - 3] * other1.value.back()) /
                 ((long long)1e9 * (long long)1e9);
      }
    }
    if (s1 + s2 - 1 == s - 1) {
      other += other1.value.back() * other2.value.back();
      if (s1 >= 2) {
        other += ((long double)other1.value[s1 - 2] * other2.value.back()) /
                 (long long)1e9;
      }
      if (s2 >= 2) {
        other += ((long double)other2.value[s2 - 2] * other1.value.back()) /
                 (long long)1e9;
      }
      other /= (long long)1e9;
    }
    if (s1 + s2 - 1 == s - 2) {
      other += other1.value.back() * other2.value.back();
      other /= (long long)1e9 * (long long)1e9;
    }
    return other / current;
  }
  string stringify() {
    string out = to_string(value.back());
    for (int i = value.size() - 1 - 1; i > -1; i -= 1) {
      string cur = to_string(value[i] + (long long)1e9);
      out += cur.substr(1);
    }
    return out;
  }
};
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long triangle(long long x) { return ((x + 1) * x) / 2; }
long long antitriangle(long long x) {
  long long low = 0, high = 2 * 998244353;
  while (low < high) {
    long long mid = (low + high + 1) / 2;
    if (triangle(mid) <= x) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  return low;
}
long long modInverse(long long a) {
  long long m = 998244353;
  long long y = 0, x = 1;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) {
    x += 998244353;
  }
  return x;
}
long long modInverse(long long a, long long b) {
  long long m = b;
  long long y = 0, x = 1;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) {
    x += b;
  }
  return x;
}
long long pow(long long a, long long b) {
  if (b == 0) {
    return 1;
  }
  if (b % 2 == 0) {
    return pow((a * a) % 998244353, b / 2) % 998244353;
  }
  return (a * pow((a * a) % 998244353, b / 2)) % 998244353;
}
long long pow(long long a, long long b, long long m) {
  if (b == 0) {
    return 1;
  }
  if (b % 2 == 0) {
    return pow((a * a) % m, b / 2, m) % m;
  }
  return (a * pow((a * a) % m, b / 2, m)) % m;
}
vector<long long> dev(vector<pair<long long, long long> > divisors) {
  if (divisors.size() == 0) {
    vector<long long> cur;
    cur.push_back(1);
    return cur;
  }
  long long x = divisors.back().first;
  long long n = divisors.back().second;
  divisors.pop_back();
  vector<long long> ans = dev(divisors);
  vector<long long> cur;
  long long xi = 1;
  for (int i = 0; i < n + 1; i += 1) {
    for (int j = 0; j < ans.size(); j += 1) {
      cur.push_back(ans[j] * xi);
    }
    xi *= x;
  }
  return cur;
}
bool isprime(long long a) {
  if (a == 1) {
    return false;
  }
  for (int i = 2; i * i <= a; i++) {
    if (a % i == 0) {
      return false;
    }
  }
  return true;
}
void add(vector<int>& x, vector<int>& y) {
  for (int i = 0; i < x.size(); i += 1) {
    x[i] += y[i];
  }
}
vector<long long> mul(vector<long long> x, long long a) {
  for (int i = 0; i < x.size(); i += 1) {
    x[i] = (x[i] * a) % 998244353;
  }
  return x;
}
vector<long long> add(vector<long long> x, vector<long long>& y) {
  for (int i = 0; i < x.size(); i += 1) {
    x[i] = (x[i] + y[i]) % 998244353;
  }
  return x;
}
int lca(vector<vector<int> >& f, vector<int>& depth, int a, int b) {
  if (depth[a] < depth[b]) {
    swap(a, b);
  }
  for (int k = 0; k < 22; k += 1) {
    if ((depth[a] - depth[b]) & (1 << k)) {
      a = f[k][a];
    }
  }
  if (a == b) {
    return a;
  }
  for (int k = 22 - 1; k > -1; k -= 1) {
    if (f[k][a] != f[k][b]) {
      a = f[k][a];
      b = f[k][b];
    }
  }
  return f[0][a];
}
struct pt {
  long long x, y;
  long long d() const { return x * x + y * y; }
};
inline pt operator-(const pt& a) { return {-a.x, -a.y}; }
inline pt operator+(const pt& a, const pt& b) { return {a.x + b.x, a.y + b.y}; }
inline pt operator-(const pt& a, const pt& b) { return {a.x - b.x, a.y - b.y}; }
inline long long operator*(const pt& a, const pt& b) {
  return a.x * b.y - a.y * b.x;
}
inline bool operator<(const pt& a, const pt& b) { return a * b < 0; }
bool llll(const pt& a, const pt& b) { return a * b > 0; }
inline bool operator<=(const pt& a, const pt& b) { return a * b <= 0; }
inline long long operator/(const pt& a, const pt& b) {
  return a.x * b.x + a.y * b.y;
}
inline bool operator==(const pt& a, const pt& b) {
  return a.x == b.x && a.y == b.y;
}
inline bool operator!=(const pt& a, const pt& b) {
  return a.x != b.x || a.y != b.y;
}
struct stringtree {
  stringtree* sons[26];
  int num = 0;
  int func(char a) { return a - 'a'; }
  stringtree() {
    num = 0;
    for (int i = 0; i < 26; i += 1) {
      sons[i] = NULL;
    }
  }
  void add(int p, string& x) {
    if (x.size() == p) {
      num++;
      return;
    }
    if (sons[func(x[p])] == NULL) {
      sons[func(x[p])] = new stringtree();
    }
    sons[func(x[p])]->add(p + 1, x);
  }
  void add(string x) { add(0, x); }
  vector<int> find(int p, string& x) {
    if (p == x.size()) {
      vector<int> r;
      if (num) {
        r.push_back(p);
      }
      return r;
    }
    vector<int> r;
    if (sons[func(x[p])] != NULL) {
      r = sons[func(x[p])]->find(p + 1, x);
    }
    if (num) {
      r.push_back(p);
    }
    return r;
  }
  vector<int> find(string x) { return find(0, x); }
};
pt o = {0, 0};
bool comp(pt a, pt b) {
  if ((a - o) * (b - o) != 0) return (a - o) * (b - o) < 0;
  return (a - o).d() < (b - o).d();
}
bool decreasing(int a, int b) { return a > b; }
struct booleantree {
  booleantree* left = NULL;
  booleantree* right = NULL;
  void add(int val) {
    booleantree* cur = this;
    for (int i = 30 - 1; i > -1; i -= 1) {
      if ((val & (1 << i))) {
        if (cur->right == NULL) {
          cur->right = new booleantree();
        }
        cur = cur->right;
      } else {
        if (cur->left == NULL) {
          cur->left = new booleantree();
        }
        cur = cur->left;
      }
    }
  }
  int find(int val) {
    booleantree* cur = this;
    int ans = 0;
    for (int i = 30 - 1; i > -1; i -= 1) {
      if ((val & (1 << i))) {
        if (cur->left == NULL) {
          cur = cur->right;
        } else {
          cur = cur->left;
          ans += (1 << i);
        }
      } else {
        if (cur->right == NULL) {
          cur = cur->left;
        } else {
          cur = cur->right;
          ans += (1 << i);
        }
      }
    }
    return ans;
  }
};
struct segtremin {
  vector<vector<long long> > arr;
  int n;
  int curlogn;
  segtremin(int size, int logni) {
    n = size;
    curlogn = logni;
    arr.resize(curlogn);
    for (int i = 0; i < curlogn; i += 1) {
      arr[i].resize(size + 1);
    }
  }
  inline long long val(int start, int end) {
    if (end >= n) {
      end = n - 1;
    }
    if (start < 0) {
      start = 0;
    }
    long long mini = 7000000000000000007;
    for (int i = 0; i < curlogn; i += 1) {
      if (start > end) {
        break;
      }
      if ((end & 1) == 0) {
        mini = min(mini, arr[i][end]);
        ;
        end--;
        if (end < 0) {
          break;
        }
      }
      if ((start & 1)) {
        mini = min(mini, arr[i][start]);
        start++;
      }
      start /= 2;
      end /= 2;
    }
    return mini;
  }
  inline void add(int start, long long num) {
    arr[0][start] = num;
    for (int i = 1; i < curlogn; i += 1) {
      arr[i][start >> i] =
          min(arr[i - 1][(start >> i) * 2], arr[i - 1][(start >> i) * 2 + 1]);
    }
  }
};
struct segtresum {
  vector<vector<long long> > arr;
  int n;
  int curlogn;
  segtresum(int size, int logni) {
    n = size;
    curlogn = logni;
    arr.resize(curlogn);
    for (int i = 0; i < curlogn; i += 1) {
      arr[i].resize(size + 1);
    }
  }
  inline long long val(int start, int end) {
    if (end >= n) {
      end = n - 1;
    }
    if (start < 0) {
      start = 0;
    }
    long long mini = 0;
    for (int i = 0; i < curlogn; i += 1) {
      if (start > end) {
        break;
      }
      if ((end & 1) == 0) {
        mini += arr[i][end];
        end--;
        if (end < 0) {
          break;
        }
      }
      if ((start & 1)) {
        mini += arr[i][start];
        start++;
      }
      start /= 2;
      end /= 2;
    }
    return mini;
  }
  inline void add(int start, long long num) {
    arr[0][start] = num;
    for (int i = 1; i < curlogn; i += 1) {
      arr[i][start >> i] =
          arr[i - 1][(start >> i) * 2] + arr[i - 1][(start >> i) * 2 + 1];
    }
  }
};
string op(string s) {
  string ans;
  for (int i = s.size() - 1; i > -1; i -= 1) {
    ans.push_back(s[i]);
  }
  return ans;
}
void merge(vector<int>& color, vector<vector<int> >& allcolor, int l, int r) {
  if (color[l] == color[r]) {
    return;
  }
  l = color[l];
  r = color[r];
  if (allcolor[l].size() < allcolor[r].size()) {
    swap(l, r);
  }
  for (int j = 0; j < allcolor[r].size(); j += 1) {
    color[allcolor[r][j]] = l;
    allcolor[l].push_back(allcolor[r][j]);
  }
  allcolor[r].resize(0);
}
vector<pt> conv(vector<pt> a) {
  pt left = {99999999999999, 999999999999999};
  for (int i = 0; i < a.size(); i += 1) {
    if (a[i].x < left.x || a[i].x == left.x && a[i].y > left.y) {
      left = a[i];
    }
  }
  o = left;
  for (int i = 0; i < a.size(); i += 1) {
    if (a[i] == left) {
      a[i] = a.back();
      a.pop_back();
      break;
    }
  }
  sort(a.begin(), a.end(), comp);
  vector<pt> conv(1, left);
  for (int i = 0; i < a.size(); i += 1) {
    while (conv.size() > 1) {
      if ((a[i] - conv.back()) * (conv.back() - conv[conv.size() - 2]) <= 0) {
        conv.pop_back();
      } else {
        break;
      }
    }
    conv.push_back(a[i]);
  }
  while (conv.size() > 1) {
    if ((left - conv.back()) * (conv.back() - conv[conv.size() - 2]) <= 0) {
      conv.pop_back();
    } else {
      break;
    }
  }
  return conv;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<vector<int> > cons(n);
  for (int i = 0; i < n - 1; i += 1) {
    long long a;
    cin >> a;
    long long b;
    cin >> b;
    a--;
    b--;
    cons[a].push_back(b);
    cons[b].push_back(a);
  }
  vector<int> leafs(n);
  vector<int> notdead(n);
  vector<int> stk;
  for (int i = 0; i < n; i += 1) {
    notdead[i] = cons[i].size();
    if (notdead[i] == 1) {
      stk.push_back(i);
    }
  }
  long long sum = 0;
  vector<int> goal(n);
  while (!stk.empty()) {
    int cur = stk.back();
    stk.pop_back();
    if (notdead[cur] <= 0) {
      continue;
    }
    int mid = 0;
    for (int i = 0; i < cons[cur].size(); i += 1) {
      if (notdead[cons[cur][i]] > 0) {
        mid = cons[cur][i];
      }
    }
    vector<int> arr;
    for (int i = 0; i < cons[mid].size(); i += 1) {
      if (notdead[cons[mid][i]] == 1) {
        arr.push_back(cons[mid][i]);
      } else {
        notdead[cons[mid][i]]--;
        if (notdead[cons[mid][i]] == 1) {
          stk.push_back(cons[mid][i]);
        }
      }
    }
    arr.push_back(mid);
    notdead[mid] = 0;
    goal[mid] = 1 + arr[0];
    for (int i = 0; i < arr.size() - 1; i += 1) {
      notdead[arr[i]] = 0;
      goal[arr[i]] = 1 + arr[i + 1];
    }
    sum += arr.size() * 2 - 2;
  }
  cout << sum << endl;
  for (int i = 0; i < n; i += 1) {
    cout << (goal[i]) << ' ';
  }
  cout << "" << endl;
  return 0;
}