#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;
}
