Language: C++

#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define debug(x) cout<<#x<<": "<<x<<endl
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

template <class T, class U> amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> amin(T& x, U y) {if (x > y) x = y;}

const int MAX_N = 2000;

int main(void)
{
    int N, K;
    cin >> N >> K;
    vector<int> g[MAX_N];
    REP(i, N - 1) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        g[A].pb(B);
        g[B].pb(A);
    }
    int ret = MAX_N;
    if (K % 2 == 0) {
        REP(v, N) {
            int d[MAX_N];
            fill(d, d + N, MAX_N);
            queue<int> q;
            q.push(v);
            d[v] = 0;
            while (!q.empty()) {
                int u = q.front();
                q.pop();
                if (d[u] == K) {
                    continue;
                }
                REP(i, g[u].size()) {
                    int to = g[u][i];
                    if (d[to] > d[u] + 1) {
                        d[to] = d[u] + 1;
                        q.push(to);
                    }
                }
            }
            int n_remove = 0;
            REP(i, N) {
                if (d[i] > K / 2) {
                    n_remove++;
                }
            }
            ret = min(ret, n_remove);
        }
    } else {
        REP(v, N) REP (j, g[v].size()) {
            int u = g[v][j];
            int d[MAX_N];
            fill(d, d + N, MAX_N);
            queue<int> q;
            q.push(v);
            q.push(u);
            d[v] = 0;
            d[u] = 0;
            while (!q.empty()) {
                int u = q.front();
                q.pop();
                if (d[u] == K) {
                    continue;
                }
                REP(i, g[u].size()) {
                    int to = g[u][i];
                    if (d[to] > d[u] + 1) {
                        d[to] = d[u] + 1;
                        q.push(to);
                    }
                }
            }
            int n_remove = 0;
            REP(i, N) {
                if (d[i] > K / 2) {
                    n_remove++;
                }
            }
            ret = min(ret, n_remove);
        }
    }
    cout << ret << endl;
    return 0;
}


Compiler output:
a.cc:33:29: error: ISO C++ forbids declaration of 'amax' with no type [-fpermissive]
   33 | template <class T, class U> amax(T& x, U y) {if (x < y) x = y;}
      |                             ^~~~
a.cc: In function 'int amax(T&, U)':
a.cc:33:63: warning: no return statement in function returning non-void [-Wreturn-type]
   33 | template <class T, class U> amax(T& x, U y) {if (x < y) x = y;}
      |                                                               ^
a.cc: At global scope:
a.cc:34:29: error: ISO C++ forbids declaration of 'amin' with no type [-fpermissive]
   34 | template <class T, class U> amin(T& x, U y) {if (x > y) x = y;}
      |                             ^~~~
a.cc: In function 'int amin(T&, U)':
a.cc:34:63: warning: no return statement in function returning non-void [-Wreturn-type]
   34 | template <class T, class U> amin(T& x, U y) {if (x > y) x = y;}
      |                                                               ^