Language: C++

#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>

using namespace std;

#define TT1T2 template<class T1, class T2>
TT1T2 void debug_print_array(const T1 &a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cerr << a[i] << (i + 1 != sz ? "," : ""); cout << endl; }
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DA(a,n) cerr<<#a<<"=["; debug_print_array(a,n); cerr<<"]\n"
double __begin;
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <typename T, const int N> using Graph = vector <T> [N];
const int MAXN = 2222;
const int INF = 1e9;
Graph<int, MAXN> g;
int d[MAXN][MAXN];
bool used[MAXN];
int h[MAXN];
int n, k;

void dfs(int vertex) {
    used[vertex] = true;

    h[vertex] = 1;

    vector <int> v;
    for (int& to : g[vertex]) {

        if (!used[to]) {
            dfs(to);
            h[vertex] = max(h[vertex], h[to] + 1);
            v.push_back(to);
        }
    }


    for (int i = 0; i <= min(k, h[vertex]); i++) {
        if (i == 0) {
            int sz = 0;
            for (int to : v) {
                sz += d[to][0];
            }
            sz++;
            d[vertex][0] = sz;
            continue;
        }

        d[vertex][i] = INF;
        for (int j = 0; j < v.size(); j++) {
            int cur = v[j];
            if (h[cur] >= i - 1) {
                int cnt = d[cur][i - 1];
                for (int p = 0; p < v.size(); p++) {
                    if (p == j) {
                        continue;
                    }
                    cnt += d[v[p]][min(h[v[p]], min(k - i, i - 1))];
                }
                if (cnt < d[vertex][i]) {
                    d[vertex][i] = cnt;
                }
            }
        }
    }
    if (h[vertex] == 1) {
        d[vertex][1] = 0;
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(20);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    cin >> n >> k;
    k++;

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

    int ans = INF;
    for (int j = 0; j < n; j++) {
        memset(used, 0, sizeof(used));
        dfs(j);
        for (int i = 0; i <= min(k, h[j]); i++) {
            ans = min(ans, d[j][i]);
        }
    }
    cout << ans << endl;


    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:107:9: error: 'memset' was not declared in this scope
  107 |         memset(used, 0, sizeof(used));
      |         ^~~~~~
a.cc:11:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   10 | #include <array>
  +++ |+#include <cstring>
   11 |