Language: C++

#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<int,int>
#define vint vector<int>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
int read(){
	int g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const int N=2e5+5;
struct Edge{
	int to,ne;
}e[N<<1];
int h[N],cnt,son[N],size[N],maxn[N],ans[N],d[N],n;
void add(int x,int y){
	e[++cnt]=(Edge){y,h[x]};
	h[x]=cnt;
}
void calc(int x,int fa,int val){
	son[x]=1;
	for(int i=h[x];i;i=e[i].ne){
		int y=e[i].to;
		if(y==fa||y>val)continue;
		calc(y,x,val);
		son[x]+=son[y];
	}
}
void dfs1(int x,int fa){
	maxn[x]=max(maxn[fa],x);size[x]=1;
	for(int i=h[x];i;i=e[i].ne){
		int y=e[i].to;
		if(y==fa)continue;
		dfs1(y,x);size[x]+=size[y];d[x]+=d[y];
	}
	if(maxn[x]==x)calc(x,fa,maxn[fa]),d[x]=-size[x];
	if(maxn[fa]==fa)d[x]+=size[x];
}
void dfs2(int x,int fa){
	if(fa){
		if(maxn[x]==x)ans[x]+=son[x];
		else if(maxn[fa]==fa)ans[x]-=son[x],ans[x]+=d[x];
		ans[x]+=ans[fa];
	}
	for(int i=h[x];i;i=e[i].ne){
		int y=e[i].to;
		if(y!=fa)dfs2(y,x);
	}
}
signed main(){
	n=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y),add(y,x);
	}dfs1(1,0);dfs2(1,0);
	for(int i=2;i<=n;i++)cout<<ans[i]<<' ';
	return signed();
}

Compiler output:
a.cc: In function 'void dfs1(int, int)':
a.cc:40:33: error: reference to 'size' is ambiguous
   40 |         maxn[x]=max(maxn[fa],x);size[x]=1;
      |                                 ^~~~
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,
                 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:25:21: note:                 'int size [200005]'
   25 | int h[N],cnt,son[N],size[N],maxn[N],ans[N],d[N],n;
      |                     ^~~~
a.cc:44:27: error: reference to 'size' is ambiguous
   44 |                 dfs1(y,x);size[x]+=size[y];d[x]+=d[y];
      |                           ^~~~
/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:25:21: note:                 'int size [200005]'
   25 | int h[N],cnt,son[N],size[N],maxn[N],ans[N],d[N],n;
      |                     ^~~~
a.cc:44:36: error: reference to 'size' is ambiguous
   44 |                 dfs1(y,x);size[x]+=size[y];d[x]+=d[y];
      |                                    ^~~~
/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:25:21: note:                 'int size [200005]'
   25 | int h[N],cnt,son[N],size[N],maxn[N],ans[N],d[N],n;
      |                     ^~~~
a.cc:46:49: error: reference to 'size' is ambiguous
   46 |         if(maxn[x]==x)calc(x,fa,maxn[fa]),d[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:25:21: note:                 'int size [200005]'
   25 | int h[N],cnt,son[N],size[N],maxn[N],ans[N],d[N],n;
      |                     ^~~~
a.cc:47:31: error: reference to 'size' is ambiguous
   47 |         if(maxn[fa]==fa)d[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:25:21: note:                 'int size [200005]'
   25 | int h[N],cnt,son[N],size[N],maxn[N],ans[N],d[N],n;
      |                     ^~~~