Language: C++

#include<bits/stdc++.h>
#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=nxt[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],nxt[mn*2];
void insert(int u,int v){
    to[++gra]=v;
    nxt[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(){
    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-ans);
    return 0;
}

Compiler output:
a.cc: In function 'void insert(int, int)':
a.cc:13:14: error: reference to 'begin' is ambiguous
   13 |     nxt[gra]=begin[u];
      |              ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:1:
/usr/include/c++/14/valarray:1238:5: note: candidates are: 'template<class _Tp> const _Tp* std::begin(const valarray<_Tp>&)'
 1238 |     begin(const valarray<_Tp>& __va) noexcept
      |     ^~~~~
/usr/include/c++/14/valarray:1227:5: note:                 'template<class _Tp> _Tp* std::begin(valarray<_Tp>&)'
 1227 |     begin(valarray<_Tp>& __va) noexcept
      |     ^~~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:95:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])'
   95 |     begin(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:63:5: note:                 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)'
   63 |     begin(const _Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:52:5: note:                 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)'
   52 |     begin(_Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
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 /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/initializer_list:88:5: note:                 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)'
   88 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
a.cc:10:29: note:                 'int begin [2003]'
   10 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],nxt[mn*2];
      |                             ^~~~~
a.cc:14:5: error: reference to 'begin' is ambiguous
   14 |     begin[u]=gra;
      |     ^~~~~
/usr/include/c++/14/valarray:1238:5: note: candidates are: 'template<class _Tp> const _Tp* std::begin(const valarray<_Tp>&)'
 1238 |     begin(const valarray<_Tp>& __va) noexcept
      |     ^~~~~
/usr/include/c++/14/valarray:1227:5: note:                 'template<class _Tp> _Tp* std::begin(valarray<_Tp>&)'
 1227 |     begin(valarray<_Tp>& __va) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:95:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])'
   95 |     begin(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:63:5: note:                 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)'
   63 |     begin(const _Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:52:5: note:                 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)'
   52 |     begin(_Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/include/c++/14/initializer_list:88:5: note:                 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)'
   88 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
a.cc:10:29: note:                 'int begin [2003]'
   10 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],nxt[mn*2];
      |                             ^~~~~
a.cc: In function 'void dfs(int, int, int)':
a.cc:7:27: error: reference to 'begin' is ambiguous
    7 | #define fr(i,j) for(int i=begin[j];i;i=nxt[i])
      |                           ^~~~~
a.cc:19:5: note: in expansion of macro 'fr'
   19 |     fr(i,p)if(to[i]!=q)
      |     ^~
/usr/include/c++/14/valarray:1238:5: note: candidates are: 'template<class _Tp> const _Tp* std::begin(const valarray<_Tp>&)'
 1238 |     begin(const valarray<_Tp>& __va) noexcept
      |     ^~~~~
/usr/include/c++/14/valarray:1227:5: note:                 'template<class _Tp> _Tp* std::begin(valarray<_Tp>&)'
 1227 |     begin(valarray<_Tp>& __va) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:95:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])'
   95 |     begin(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:63:5: note:                 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)'
   63 |     begin(const _Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/include/c++/14/bits/range_access.h:52:5: note:                 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)'
   52 |     begin(_Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/include/c++/14/initializer_list:88:5: note:                 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)'
   88 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
a.cc:10:29: note:                 'int begin [2003]'
   10 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],nxt[mn*2];
      |                             ^~~~~