Language: C++

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LF double
#define LL long long
#define ULL unsigned int
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define fd(i,j,k) for(int i=j;i>=k;i--)
#define fr(i,j) for(int i=begin[j];i;i=next[i])
using namespace std;
int const mn=2*1e3+3,mo=1e9+7;
int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2];
void insert(int u,int v){
    to[++gra]=v;
    next[gra]=begin[u];
    begin[u]=gra;
}
void dfs(int p,int q,int dep){
    tmp++;
    if(!dep)return;
    fr(i,p)if(to[i]!=q)
        dfs(to[i],p,dep-1);
}
int main(){
    freopen("c.in","r",stdin);
    freopen("c.out","w",stdout);
    scanf("%d%d",&n,&K);
    fo(i,1,n-1){
        scanf("%d%d",&u[i],&v[i]);
        insert(u[i],v[i]);
        insert(v[i],u[i]);
    }
    int ans=0;
    if(K&1){
        fo(i,1,n-1){
            tmp=0;
            dfs(u[i],v[i],K/2);
            dfs(v[i],u[i],K/2);
            ans=max(ans,tmp);
        }
    }else{
        fo(i,1,n){
            tmp=0;
            dfs(i,0,K/2);
            ans=max(ans,tmp);
        }
    }
    printf("%d\n",n-ans);
    return 0;
}


Compiler output:
a.cc: In function 'void insert(int, int)':
a.cc:16:5: error: reference to 'next' is ambiguous
   16 |     next[gra]=begin[u];
      |     ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:2:
/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:13:48: note:                 'int next [4006]'
   13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2];
      |                                                ^~~~
a.cc:16:15: error: reference to 'begin' is ambiguous
   16 |     next[gra]=begin[u];
      |               ^~~~~
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
                 from /usr/include/c++/14/bits/stl_algo.h:59,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)'
   88 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
a.cc:13:29: note:                 'int begin [2003]'
   13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2];
      |                             ^~~~~
a.cc:17:5: error: reference to 'begin' is ambiguous
   17 |     begin[u]=gra;
      |     ^~~~~
/usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)'
   88 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
a.cc:13:29: note:                 'int begin [2003]'
   13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2];
      |                             ^~~~~
a.cc: In function 'void dfs(int, int, int)':
a.cc:10:27: error: reference to 'begin' is ambiguous
   10 | #define fr(i,j) for(int i=begin[j];i;i=next[i])
      |                           ^~~~~
a.cc:22:5: note: in expansion of macro 'fr'
   22 |     fr(i,p)if(to[i]!=q)
      |     ^~
/usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)'
   88 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
a.cc:13:29: note:                 'int begin [2003]'
   13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2];
      |                             ^~~~~
a.cc:10:40: error: reference to 'next' is ambiguous
   10 | #define fr(i,j) for(int i=begin[j];i;i=next[i])
      |                                        ^~~~
a.cc:22:5: note: in expansion of macro 'fr'
   22 |     fr(i,p)if(to[i]!=q)
      |     ^~
/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:13:48: note:                 'int next [4006]'
   13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2];
      |                                                ^~~~