Problem:
Score : 600 points

Problem Statement

Given an undirected tree, let the distance between vertices u and v be the
number of edges on the simple path from u to v.
The diameter of a tree is the maximum among the distances between any two vertices.
We will call a tree good if and only if its diameter is at most K.

You are given an undirected tree with N vertices numbered 1 through N.
For each i (1≦i≦N-1), there is an edge connecting vertices A_i and B_i.

You want to remove zero or more vertices from the tree, so that the resulting tree is good.
When a vertex is removed, all incident edges will also be removed.
The resulting graph must be connected.

Find the minimum number of vertices that you need to remove in order to produce a good tree.

Constraints

2≦N≦2000

1≦K≦N-1

1≦A_i≦N, 1≦B_i≦N

The graph defined by A_i and B_i is a tree.

Input

The input is given from Standard Input in the following format:

N K
A_1 B_1
A_2 B_2
:
A_{N-1} B_{N-1}

Output

Print the minimum number of vertices that you need to remove in order to produce a good tree.

Sample Input 1

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

Sample Output 1

2

The tree is shown below. Removing vertices 5 and 6 will result in a good tree with the diameter of 2.

Sample Input 2

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

Sample Output 2

0

Since the given tree is already good, you do not need to remove any vertex.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
typedef vector<int> vi;typedef vector<vi> vvi;typedef pair<int,int> pii;typedef vector<pii> vpii;
typedef long long ll;

vvi E;
vi D;
int N, K;

void dfs(int cur, int pre) {
  forr(nex, E[cur]) {
    if (nex != pre) {
      D[nex] = D[cur] + 1;
      dfs(nex, cur);
    }
  }
}

void Main() {
  scanf("%d%d", &N, &K);
  E.resize(N);
  rep(i, N-1) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--; v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }

  if (K == 1) {
    _p("%d\n", N-2);
    return;
  }

  D.resize(N);

  int ans = 1e9;
  if (K % 2) {
    rep(i, N) forr(j, E[i]) if (i < j) {
      int cand = 0;
      fill(ALL(D), 0);
      dfs(i, j);
      sort(ALL(D));
      cand += N - distance(D.begin(), upper_bound(ALL(D), K/2));

      fill(ALL(D), 0);
      dfs(j, i);
      sort(ALL(D));
      cand += N - distance(D.begin(), upper_bound(ALL(D), K/2));
      ans = min(ans, cand);
    }
  }
  else {
    rep(i, N) {
      D[i] = 0;
      dfs(i, -1);
      sort(ALL(D));
      int cand = N - distance(D.begin(), upper_bound(ALL(D), K/2));
      ans = min(ans, cand);
    }
  }
  _p("%d\n", ans);
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }