Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long

using namespace std;

int N, K;

vector<int> next[2000];

int dfs(int now, int prev, int left) {
    if (left == 0) return 1;

    int ret = 0;
    for (int i = 0; i < next[now].size(); i++) {
	if (prev == next[now][i]) continue;
	ret += dfs(next[now][i], now, left - 1);
    }

    return ret + 1;
}

int count(int num) {
    return dfs(num, -1, K);
}

signed main() {
    cin >> N >> K;

    for (int i = 0; i < N-1; i++) {
	int A, B;
	cin >> A >> B;
	A--; B--;
	next[A].push_back(B);
	next[B].push_back(A);
    }

    int ret = 0;
    for (int i = 0; i < N; i++) {
	if (next[i].size() >= 2) continue;

	ret = max(count(i), ret);
    }

    cout << (N - ret) << endl;

    return 0;
}


Compiler output:
a.cc: In function 'long long int dfs(long long int, long long int, long long int)':
a.cc:29:25: error: reference to 'next' is ambiguous
   29 |     for (int i = 0; i < next[now].size(); i++) {
      |                         ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:13: note:                 'std::vector<long long int> next [2000]'
   23 | vector<int> next[2000];
      |             ^~~~
a.cc:30:21: error: reference to 'next' is ambiguous
   30 |         if (prev == next[now][i]) continue;
      |                     ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:13: note:                 'std::vector<long long int> next [2000]'
   23 | vector<int> next[2000];
      |             ^~~~
a.cc:31:20: error: reference to 'next' is ambiguous
   31 |         ret += dfs(next[now][i], now, left - 1);
      |                    ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:13: note:                 'std::vector<long long int> next [2000]'
   23 | vector<int> next[2000];
      |             ^~~~
a.cc: In function 'int main()':
a.cc:48:9: error: reference to 'next' is ambiguous
   48 |         next[A].push_back(B);
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:13: note:                 'std::vector<long long int> next [2000]'
   23 | vector<int> next[2000];
      |             ^~~~
a.cc:49:9: error: reference to 'next' is ambiguous
   49 |         next[B].push_back(A);
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:13: note:                 'std::vector<long long int> next [2000]'
   23 | vector<int> next[2000];
      |             ^~~~
a.cc:54:13: error: reference to 'next' is ambiguous
   54 |         if (next[i].size() >= 2) continue;
      |             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:13: note:                 'std::vector<long long int> next [2000]'
   23 | vector<int> next[2000];
      |             ^~~~