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;
int T, N;
vector<int> g[100101];
long long dp[100101][3];
int ty[100101];
vector<vector<int> > rem[100101][3];
int sav[100101];
int ans[100101];
long long f(long long n) { return -n * 1234567890LL + n * 2; }
void DFS(int n, int prev) {
  dp[n][0] = dp[n][1] = dp[n][2] = 1234567890LL;
  long long sum = 0;
  long long mx1_1 = -1234567890LL, mx1_2 = -1234567890LL, mx2 = -1234567890LL;
  int midx1_1 = 0, midx1_2 = 0, midx2 = 0;
  long long cnt = 0, cnt1_1 = 0, cnt1_2 = 0, cnt2 = 0;
  for (int next : g[n]) {
    if (next == prev) continue;
    DFS(next, n);
    if (dp[next][0] == 1234567890LL) cnt++;
    sum += dp[next][0];
    long long val;
    if (dp[next][1] != 1234567890LL) {
      val = dp[next][0] - dp[next][1];
      if (mx1_1 < val) {
        mx1_2 = mx1_1, midx1_2 = midx1_1, cnt1_2 = cnt1_1;
        mx1_1 = val, midx1_1 = next,
        cnt1_1 = (dp[next][0] == 1234567890LL) ? 1 : 0;
      } else if (mx1_2 < val)
        mx1_2 = val, midx1_2 = next,
        cnt1_2 = (dp[next][0] == 1234567890LL) ? 1 : 0;
    }
    if (dp[next][2] != 1234567890LL) {
      val = dp[next][0] - dp[next][2];
      if (mx2 < val)
        mx2 = val, midx2 = next, cnt2 = (dp[next][0] == 1234567890LL) ? 1 : 0;
    }
  }
  long long val;
  val = sum - mx1_1 - mx1_2 + 4 + f(cnt - cnt1_1 - cnt1_2);
  if (cnt - cnt1_1 - cnt1_2 != 1 && midx1_1 && midx1_2 && dp[n][0] > val) {
    dp[n][0] = val;
    ty[n] = 0;
    rem[n][0].clear();
    rem[n][0].push_back({n, midx1_1, midx1_2});
    int p = -1;
    for (int next : g[n]) {
      if (next == prev) continue;
      if (next == midx1_1 || next == midx1_2 || dp[next][0] != 1234567890LL)
        continue;
      if (p == -1)
        p = next;
      else
        rem[n][0].push_back({p, next}), p = -1;
    }
    if (p != -1) rem[n][0].back().push_back(p);
  }
  val = sum - mx2 + 4 + f(cnt - cnt2);
  if (cnt - cnt2 != 1 && midx2 && dp[n][0] > val) {
    dp[n][0] = val;
    ty[n] = 1;
    rem[n][0].clear();
    rem[n][0].push_back({n, midx2, sav[midx2]});
    int p = -1;
    for (int next : g[n]) {
      if (next == prev) continue;
      if (next == midx2 || dp[next][0] != 1234567890LL) continue;
      if (p == -1)
        p = next;
      else
        rem[n][0].push_back({p, next}), p = -1;
    }
    if (p != -1) rem[n][0].back().push_back(p);
  }
  val = sum - mx1_1 + 2 + f(cnt - cnt1_1);
  if (cnt - cnt1_1 != 1 && midx1_1 && dp[n][0] > val) {
    dp[n][0] = val;
    ty[n] = 2;
    rem[n][0].clear();
    rem[n][0].push_back({n, midx1_1});
    int p = -1;
    for (int next : g[n]) {
      if (next == prev) continue;
      if (next == midx1_1 || dp[next][0] != 1234567890LL) continue;
      if (p == -1)
        p = next;
      else
        rem[n][0].push_back({p, next}), p = -1;
    }
    if (p != -1) rem[n][0].back().push_back(p);
  }
  val = sum + f(cnt);
  if (cnt != 1 && dp[n][1] > val) {
    dp[n][1] = val;
    rem[n][1].clear();
    int p = -1;
    for (int next : g[n]) {
      if (next == prev) continue;
      if (dp[next][0] != 1234567890LL) continue;
      if (p == -1)
        p = next;
      else
        rem[n][1].push_back({p, next}), p = -1;
    }
    if (p != -1) rem[n][1].back().push_back(p);
  }
  val = sum - mx1_1 + f(cnt - cnt1_1);
  if (cnt - cnt1_1 != 1 && dp[n][2] > val) {
    dp[n][2] = val;
    sav[n] = midx1_1;
    rem[n][2].clear();
    int p = -1;
    for (int next : g[n]) {
      if (next == prev) continue;
      if (next == midx1_1 || dp[next][0] != 1234567890LL) continue;
      if (p == -1)
        p = next;
      else
        rem[n][2].push_back({p, next}), p = -1;
    }
    if (p != -1) rem[n][2].back().push_back(p);
  }
}
void DFS2(int n, int prev, int x) {
  for (auto &v : rem[n][x]) {
    if (v.size() == 2)
      ans[v[0]] = v[1], ans[v[1]] = v[0];
    else if (v.size() == 3)
      ans[v[0]] = v[1], ans[v[1]] = v[2], ans[v[2]] = v[0];
  }
  if (x == 0) {
    if (ty[n] == 0) {
      for (int next : g[n]) {
        if (next == prev) continue;
        if (next == rem[n][0][0][1] || next == rem[n][0][0][2])
          DFS2(next, n, 1);
        else
          DFS2(next, n, 0);
      }
    } else if (ty[n] == 1) {
      for (int next : g[n]) {
        if (next == prev) continue;
        if (next == rem[n][0][0][1])
          DFS2(next, n, 2);
        else
          DFS2(next, n, 0);
      }
    } else if (ty[n] == 2) {
      for (int next : g[n]) {
        if (next == prev) continue;
        if (next == rem[n][0][0][1])
          DFS2(next, n, 1);
        else
          DFS2(next, n, 0);
      }
    }
  } else if (x == 1) {
    for (int next : g[n]) {
      if (next == prev) continue;
      DFS2(next, n, 0);
    }
  } else if (x == 2) {
    for (int next : g[n]) {
      if (next == prev) continue;
      if (next == sav[n])
        DFS2(next, n, 1);
      else
        DFS2(next, n, 0);
    }
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  DFS(1, 0);
  DFS2(1, 0, 0);
  for (int i = 1; i <= N; i++)
    if (ans[i] == 0) assert(0);
  printf("%lld\n", dp[1][0]);
  for (int i = 1; i <= N; i++) printf("%d ", ans[i]);
  return 0;
}