#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100005;
int n, nn, a[N][2], lst[N], sz[N], len;
int ans[N][2], idx, num[N], d[N], ptr;
bool vis[N];
inline void add_edge(int x, int y) {
  a[++len][0] = y;
  a[len][1] = lst[x];
  lst[x] = len;
}
void add(int x, int y) {
  ans[++idx][0] = x;
  ans[idx][1] = y;
}
int dfs1(int pos, int fa) {
  int ret = 1;
  for (int i = lst[pos]; i > 0; i = a[i][1])
    if (a[i][0] != fa && !vis[a[i][0]]) ret += dfs1(a[i][0], pos);
  return ret;
}
void dfs2(int pos, int fa, int v) {
  sz[pos] = 1;
  num[pos] = v;
  for (int i = lst[pos]; i > 0; i = a[i][1])
    if (a[i][0] != fa && !vis[a[i][0]]) {
      dfs2(a[i][0], pos, v);
      sz[pos] += sz[a[i][0]];
    }
  if (sz[pos] >= nn) d[++ptr] = pos, sz[pos] = 0;
}
void dfs3(int pos, int fa, int st) {
  if (!vis[pos]) add(st, pos);
  for (int i = lst[pos]; i > 0; i = a[i][1])
    if (a[i][0] != fa && !vis[a[i][0]]) dfs3(a[i][0], pos, st);
}
void solve(int pos, int v, int l) {
  int ss = dfs1(pos, 0);
  nn = sqrt(ss);
  dfs2(pos, 0, v);
  int r = ptr;
  for (int i = l; i < r; i++)
    for (int j = i + 1; j <= r; j++) add(d[i], d[j]);
  for (int i = l; i <= r; i++) vis[d[i]] = 1;
  for (int i = l; i <= r; i++) dfs3(d[i], 0, d[i]);
  for (int i = l; i <= r; i++) {
    for (int j = lst[d[i]]; j > 0; j = a[j][1])
      if (!vis[a[j][0]] && num[a[j][0]] != v + 1)
        solve(a[j][0], v + 1, ptr + 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  int kk, t1, t2;
  cin >> n >> kk;
  for (int i = 1; i < n; i++)
    cin >> t1 >> t2, add_edge(t1, t2), add_edge(t2, t1);
  solve(1, 1, 1);
  cout << idx << endl;
  for (int i = 1; i <= idx; i++) cout << ans[i][0] << ' ' << ans[i][1] << endl;
  return 0;
}
