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;
vint G[N];
int son[N],size[N],maxn[N],ans[N],d[N],n;
void calc(int x,int fa,int val){
	son[x]=1;
	for(int y:G[x]){
		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 y:G[x]){
		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 y:G[x])if(y!=fa)dfs2(y,x);
}
signed main(){
	n=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		G[x].pb(y),G[y].pb(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:33:33: error: reference to 'size' is ambiguous
   33 |         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:23:12: note:                 'int size [200005]'
   23 | int son[N],size[N],maxn[N],ans[N],d[N],n;
      |            ^~~~
a.cc:36:27: error: reference to 'size' is ambiguous
   36 |                 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:23:12: note:                 'int size [200005]'
   23 | int son[N],size[N],maxn[N],ans[N],d[N],n;
      |            ^~~~
a.cc:36:36: error: reference to 'size' is ambiguous
   36 |                 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:23:12: note:                 'int size [200005]'
   23 | int son[N],size[N],maxn[N],ans[N],d[N],n;
      |            ^~~~
a.cc:38:49: error: reference to 'size' is ambiguous
   38 |         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:23:12: note:                 'int size [200005]'
   23 | int son[N],size[N],maxn[N],ans[N],d[N],n;
      |            ^~~~
a.cc:39:31: error: reference to 'size' is ambiguous
   39 |         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:23:12: note:                 'int size [200005]'
   23 | int son[N],size[N],maxn[N],ans[N],d[N],n;
      |            ^~~~