Language: C++

//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 2020
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int f[N][N],minn[N][N];
int size[N];
int n,k;
struct edge
{
	int next,to;
}e[N<<1];
int head[N],cnt,dist[N],g[N];
inline void add_edge(int from,int to){e[++cnt]=(edge){head[from],to};head[from]=cnt;}
void dfs(int now,int father)
{
	size[now]=1;int flag=0;
	for(register int i=head[now];i;i=e[i].next)
	{
		if(e[i].to==father)continue;
		dfs(e[i].to,now);flag=1;
		size[now]+=size[e[i].to];dist[now]=max(dist[now],dist[e[i].to]+1);
		for(register int j=1;j<=k+1;j++)f[now][j]+=f[e[i].to][j];
	}
	for(register int j=0;j<=k+1;j++)g[j]=0;
	for(register int i=head[now];i;i=e[i].next)
	{
		if(e[i].to==father)continue;
		for(register int j=0;j<=k+1;j++)g[j]+=f[e[i].to][j];
	}
	f[now][0]=size[now];
	if(!flag){for(register int i=1;i<=k+1;i++)f[now][i]=0;return ;}
	for(register int j=1;j<=k+1;j++)
	{
		f[now][j]=inf;
		for(register int i=head[now];i;i=e[i].next)
		{
			if(e[i].to==father)continue;
//			cout<<"???:"<<now<<" "<<e[i].to<<" "<<j<<" "<<min(j-1,k-(j-1))<<" "<<f[e[i].to][j-1]<<" "<<g[min(j-1,k-(j-1))]-f[e[i].to][min(j-1,k-(j-1))]<<endl;
			if(min(j-1,k-(j-1))<0)continue;
			f[now][j]=min(f[now][j],f[e[i].to][j-1]+g[min(j-1,k-(j-1))]-f[e[i].to][min(j-1,k-(j-1))]);
		}
	}
	for(register int j=1;j<=k+1;j++)f[now][j]=min(f[now][j],f[now][j-1]);
//	cout<<"WTF:"<<now<<" "<<dist[now]<<endl;
//	for(register int j=0;j<=k+1;j++)cout<<f[now][j]<<" ";cout<<endl;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),k=read();
	for(register int i=1;i<n;i++)
	{
		int x=read(),y=read();
		add_edge(x,y);add_edge(y,x);
	}
	dfs(1,0);
	printf("%d\n",f[1][k+1]);
	return 0;
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:39:9: error: reference to 'size' is ambiguous
   39 |         size[now]=1;int flag=0;
      |         ^~~~
In file included from /usr/include/c++/14/string:53,
                 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:2:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [2020]'
   29 | int size[N];
      |     ^~~~
a.cc:40:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   40 |         for(register int i=head[now];i;i=e[i].next)
      |                          ^
a.cc:44:17: error: reference to 'size' is ambiguous
   44 |                 size[now]+=size[e[i].to];dist[now]=max(dist[now],dist[e[i].to]+1);
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [2020]'
   29 | int size[N];
      |     ^~~~
a.cc:44:28: error: reference to 'size' is ambiguous
   44 |                 size[now]+=size[e[i].to];dist[now]=max(dist[now],dist[e[i].to]+1);
      |                            ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [2020]'
   29 | int size[N];
      |     ^~~~
a.cc:45:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   45 |                 for(register int j=1;j<=k+1;j++)f[now][j]+=f[e[i].to][j];
      |                                  ^
a.cc:47:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   47 |         for(register int j=0;j<=k+1;j++)g[j]=0;
      |                          ^
a.cc:48:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   48 |         for(register int i=head[now];i;i=e[i].next)
      |                          ^
a.cc:51:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   51 |                 for(register int j=0;j<=k+1;j++)g[j]+=f[e[i].to][j];
      |                                  ^
a.cc:53:19: error: reference to 'size' is ambiguous
   53 |         f[now][0]=size[now];
      |                   ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [2020]'
   29 | int size[N];
      |     ^~~~
a.cc:54:36: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   54 |         if(!flag){for(register int i=1;i<=k+1;i++)f[now][i]=0;return ;}
      |                                    ^
a.cc:55:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   55 |         for(register int j=1;j<=k+1;j++)
      |                          ^
a.cc:58:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   58 |                 for(register int i=head[now];i;i=e[i].next)
      |                                  ^
a.cc:66:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   66 |         for(register int j=1;j<=k+1;j++)f[now][j]=min(f[now][j],f[now][j-1]);
      |                          ^
a.cc: In function 'int main()':
a.cc:75:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   75 |         for(register int i=1;i<n;i++)
      |                          ^