Language: C++

#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int read()
{
	char c=getchar();
	int res=0;
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') res=(res<<1)+(res<<3)+(c^48),c=getchar();
	return res;
}
int n,mv[200005],h[200005],cnt,a[200005],size[200005],num[200005],ans[200005];
struct Edge
{
	int to,next;
}w[400005];
void add(int x,int y)
{
	w[++cnt]=(Edge){y,h[x]};
	h[x]=cnt;
}
void dfs2(int x,int fa,int v)
{
	num[x]=1;
	for(int i=h[x];i;i=w[i].next)
	{
		int to=w[i].to;
		if(to==fa||to>=v) continue;
		dfs2(to,x,v);
		num[x]+=num[to];
	}
}
void dfs(int x,int fa)
{
	mv[x]=max(mv[fa],x);
	size[x]=1;
	for(int i=h[x];i;i=w[i].next)
	{
		int to=w[i].to;
		if(to==fa) continue;
		dfs(to,x);
		a[x]+=a[to];size[x]+=size[to];
	}
	if(mv[x]==x) dfs2(x,fa,mv[fa]),a[x]=-size[x];
	if(mv[fa]==fa) a[x]+=size[x];
}
void dfs3(int x,int fa)
{
	if(fa)
	{
		if(mv[x]==x) ans[x]+=num[x];
		else if(mv[fa]==fa) ans[x]-=num[x],ans[x]+=a[x];
		ans[x]+=ans[fa];
	}
	for(int i=h[x];i;i=w[i].next)
	{
		int to=w[i].to;
		if(to==fa) continue;
		dfs3(to,x);
	}
}
int main()
{
	n=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		add(x,y),add(y,x);
	}
	dfs(1,0);
	dfs3(1,0);
	for(int i=2;i<=n;i++) printf("%d ",ans[i]);
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:41:9: error: reference to 'size' is ambiguous
   41 |         size[x]=1;
      |         ^~~~
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: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:17:42: note:                 'int size [200005]'
   17 | int n,mv[200005],h[200005],cnt,a[200005],size[200005],num[200005],ans[200005];
      |                                          ^~~~
a.cc:47:29: error: reference to 'size' is ambiguous
   47 |                 a[x]+=a[to];size[x]+=size[to];
      |                             ^~~~
/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:17:42: note:                 'int size [200005]'
   17 | int n,mv[200005],h[200005],cnt,a[200005],size[200005],num[200005],ans[200005];
      |                                          ^~~~
a.cc:47:38: error: reference to 'size' is ambiguous
   47 |                 a[x]+=a[to];size[x]+=size[to];
      |                                      ^~~~
/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:17:42: note:                 'int size [200005]'
   17 | int n,mv[200005],h[200005],cnt,a[200005],size[200005],num[200005],ans[200005];
      |                                          ^~~~
a.cc:49:46: error: reference to 'size' is ambiguous
   49 |         if(mv[x]==x) dfs2(x,fa,mv[fa]),a[x]=-size[x];
      |                                              ^~~~
/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:17:42: note:                 'int size [200005]'
   17 | int n,mv[200005],h[200005],cnt,a[200005],size[200005],num[200005],ans[200005];
      |                                          ^~~~
a.cc:50:30: error: reference to 'size' is ambiguous
   50 |         if(mv[fa]==fa) a[x]+=size[x];
      |                              ^~~~
/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:17:42: note:                 'int size [200005]'
   17 | int n,mv[200005],h[200005],cnt,a[200005],size[200005],num[200005],ans[200005];
      |                                          ^~~~