#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> color(n);
  vector<int> d(n);
  vector<int> sub(n);
  int iter = 0;
  function<void(int, int, int, int)> dfs_to_color = [&](int v, int p, int c,
                                                        int pr) {
    color[v] = c;
    for (int i : g[v]) {
      if (i == p || color[i] != pr) continue;
      dfs_to_color(i, v, c, pr);
    }
  };
  function<void(int, int, int)> dfs_on_color = [&](int v, int p, int c) {
    if (~p)
      d[v] = d[p] ^ 1;
    else
      d[v] = 0;
    sub[v] = 1;
    for (int i : g[v]) {
      if (color[i] != c || i == p) continue;
      dfs_on_color(i, v, c);
      sub[v] += sub[i];
    }
  };
  vector<pair<int, int>> ret;
  function<void(vector<int>)> solve = [&](vector<int> nodes) {
    int sz = nodes.size();
    if (sz <= 4) return;
    int root = nodes[0];
    int c = color[root];
    dfs_on_color(root, -1, c);
    int pr = -1;
    while (true) {
      int nxt = -1;
      for (int i : g[root]) {
        if (color[i] != c || i == pr) continue;
        if (sub[i] > sz / 2) nxt = i;
      }
      if (nxt == -1) break;
      pr = root;
      root = nxt;
    }
    for (int i : g[root]) {
      if (color[i] != c) continue;
      iter++;
      dfs_to_color(i, root, iter, c);
    }
    map<int, vector<int>> to_color;
    for (int i : nodes) {
      if (i == root) continue;
      to_color[color[i]].push_back(i);
    }
    int pos = -1;
    int cd = 0;
    for (auto it : to_color) {
      int id = it.first;
      vector<int> nxt = it.second;
      solve(nxt);
      for (int i : nxt) color[i] = id;
      dfs_on_color(nxt[0], -1, id);
      if ((int)nxt.size() > cd) {
        cd = nxt.size();
        pos = id;
      }
    }
    for (auto it : to_color) {
      int id = it.first;
      vector<int> vertices = it.second;
      vector<int> to_root;
      if (id != pos)
        to_root = vertices;
      else {
        vector<int> cnt(2);
        for (int i : vertices) cnt[d[i]]++;
        int chosen = cnt[1] < cnt[0];
        for (int i : vertices) {
          if (d[i] == chosen) to_root.push_back(i);
        }
      }
      for (int i : to_root) {
        ret.emplace_back(i, root);
      }
    }
  };
  vector<int> foo(n);
  iota(foo.begin(), foo.end(), 0);
  solve(foo);
  assert((int)ret.size() <= 10 * n);
  cout << ret.size() << endl;
  for (auto i : ret) {
    cout << i.first + 1 << " " << i.second + 1 << "\n";
  }
  return 0;
}
