Language: C++

//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
typedef long long ll;
const int Imx=2147483647;
const int mod=1000000007;
const ll Lbg=2e18;
//My own input/output stream
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putsp()
#define putii(x,y) puti(x),putnum(y),putsp()
#define putiii(x,y,z) putii(x,y),putnum(z),putsp()
#define putsi(x) putnum(x),putendl()
#define putsii(x,y) puti(x),putnum(y),putendl()
#define putsiii(x,y,z) putii(x,y),putnum(z),putendl()
inline ll getnum()
{
	register ll r=0;register bool ng=0;register char c;c=getchar();
	while(c!='-'&&(c<'0'||c>'9'))c=getchar();
	if(c=='-')ng=1,c=getchar();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=getchar();
	if(ng)r=-r;return r;
}
template <class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline void putsp(){putchar(' ');}
inline void putendl(){putchar('\n');}
inline char mygetchar(){register char c=getchar();while(c==' '||c=='\n')c=getchar();return c;}
struct node
{
	int lazy;
	pair<int,pair<int,int> > mn;
	node(){lazy=0;mn=MP(0,0);}
}a[400111];
#define ls p<<1
#define rs p<<1|1
void pushdown(int p)
{
	if(a[p].lazy!=0)
	{
		a[ls].lazy+=a[p].lazy;
		a[rs].lazy+=a[p].lazy;
		a[ls].mn.FF+=a[p].lazy;
		a[rs].mn.FF+=a[p].lazy;
		a[p].lazy=0;
	}
}
void update(int p)
{
	a[p].mn=min(a[ls].mn,a[rs].mn);
}
void build(int l,int r,int p=1)
{
	if(l==r)
	{
		a[p].mn=MP(0,l);
		return;
	}
	build(l,m,ls);
	build(m+1,r,rs);
	update(p);
}
int coef;
void add(int x,int y,int l,int r,int p=1)
{
	if(x<=l&&r<=y)
	{
		a[p].lazy+=coef;
		a[p].mn.FF+=coef;
		return;
	}
	pushdown(p);
	int m=l+r>>1;
	if(x<=m)add(x,y,l,m,ls);
	if(m<y)add(x,y,m+1,r,rs);
	update(p);
}
int n;
vector<int>con[100111];
int dfn[100111],top[100111],son[100111],sz[100111],lv[100111],par[100111],dfntot;
void dfs0(int x)
{
	sz[x]=1;
	for(int i=0;i<con[x].size();i++)
	{
		int u=con[x][i];
		if(u==par[x])continue;
		lv[u]=lv[x]+1;
		par[u]=x;
		dfs0(u);
		sz[x]+=sz[u];
	}
}
void dfs1(int x)
{
	dfn[x]=++dfntot;
	int mx=0;
	for(int i=0;i<con[x].size();i++)
	{
		int u=con[x][i];
		if(u==par[x])continue;
		if(sz[u]>mx)mx=sz[u],son[x]=u;
	}
	if(son[x])top[son[x]]=top[x],dfs(son[x]);
	for(int i=0;i<con[x].size();i++)
	{
		int u=con[x][i];
		if(u==par[x]||u==son[x])continue;
		top[u]=u;
		dfs1(u);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		con[x].PB(y);
		con[y].PB(x);
	}
	lv[1]=1;
	dfs0(1);
	top[1]=1;
	dfs1(1);
	return 0;
}

Compiler output:
a.cc: In function 'll getnum()':
a.cc:24:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   24 |         register ll r=0;register bool ng=0;register char c;c=getchar();
      |                     ^
a.cc:24:39: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   24 |         register ll r=0;register bool ng=0;register char c;c=getchar();
      |                                       ^~
a.cc:24:58: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   24 |         register ll r=0;register bool ng=0;register char c;c=getchar();
      |                                                          ^
a.cc: In function 'void putnum(T)':
a.cc:33:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   33 |         register short a[20]={},sz=0;
      |                        ^
a.cc:33:33: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   33 |         register short a[20]={},sz=0;
      |                                 ^~
a.cc: In function 'char mygetchar()':
a.cc:40:39: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   40 | inline char mygetchar(){register char c=getchar();while(c==' '||c=='\n')c=getchar();return c;}
      |                                       ^
a.cc: In constructor 'node::node()':
a.cc:45:32: error: no match for 'operator=' (operand types are 'std::pair<int, std::pair<int, int> >' and 'std::pair<int, int>')
   45 |         node(){lazy=0;mn=MP(0,0);}
      |                                ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_pair.h:946:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U2 = _U1; _T1 = int; _T2 = std::pair<int, int>]'
  946 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:946:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h: In substitution of 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<int&, const _U1&>, std::is_assignable<std::pair<int, int>&, const _U2&> >::value, std::pair<int, std::pair<int, int> >&>::type std::pair<int, std::pair<int, int> >::operator=(const std::pair<_T1, _T2>&) [with _U1 = int; _U2 = int]':
a.cc:45:25:   required from here
   45 |         node(){lazy=0;mn=MP(0,0);}
      |                                ^
/usr/include/c++/14/bits/stl_pair.h:946:9: error: no type named 'type' in 'struct std::enable_if<false, std::pair<int, std::pair<int, int> >&>'
  946 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:957:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U2 = _U1; _T1 = int; _T2 = std::pair<int, int>]'
  957 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:957:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h: In substitution of 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<int&, _U1&&>, std::is_assignable<std::pair<int, int>&, _U2&&> >::value, std::pair<int, std::pair<int, int> >&>::type std::pair<int, std::pair<int, int> >::operator=(std::pair<_T1, _T2>&&) [with _U1 = int; _U2 = int]':
a.cc:45:25:   required from here
   45 |         node(){lazy=0;mn=MP(0,0);}
      |                                ^
/usr/include/c++/14/bits/stl_pair.h:957:9: error: no type named 'type' in 'struct std::enable_if<false, std::pair<int, std::pair<int, int> >&>'
  957 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:921:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&>) [with _T1 = int; _T2 = std::pair<int, int>; std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&> = const std::pair<int, std::pair<int, int> >&]'
  921 |       operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:923:65: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::__conditional_t<true, const std::pair<int, std::pair<int, int> >&, const std::__nonesuch&>' {aka 'const std::pair<int, std::pair<int, int> >&'}
  921 |       operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  922 |                                        is_copy_assignable<_T2>>::value,
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  923 |                                 const pair&, const __nonesuch&> __p)
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_pair.h:931:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&>) [with _T1 = int; _T2 = std::pair<int, int>; std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&> = std::pair<int, std::pair<int, int> >&&]'
  931 |       operator=(__conditional_t<__and_<is_move_assignable<_T1>,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:933:55: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::__conditional_t<true, std::pair<int, std::pair<int, int> >&&, std::__nonesuch&&>' {aka 'std::pair<int, std::pair<int, int> >&&'}
  931 |       operator=(__conditional_t<__and_<is_move_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  932 |                                        is_move_assignable<_T2>>::value,
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  933 |                                 pair&&, __nonesuch&&> __p)
      |                                 ~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc: In function 'void build(int, int, int)':
a.cc:68:31: error: no match for 'operator=' (operand types are 'std::pair<int, std::pair<int, int> >' and 'std::pair<int, int>')
   68 |                 a[p].mn=MP(0,l);
      |                               ^
/usr/include/c++/14/bits/stl_pair.h:946:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U2 = _U1; _T1 = int; _T2 = std::pair<int, int>]'
  946 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:946:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h: In substitution of 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<int&, const _U1&>, std::is_assignable<std::pair<int, int>&, const _U2&> >::value, std::pair<int, std::pair<int, int> >&>::type std::pair<int, std::pair<int, int> >::operator=(const std::pair<_T1, _T2>&) [with _U1 = int; _U2 = int]':
a.cc:68:17:   required from here
   68 |                 a[p].mn=MP(0,l);
      |                               ^
/usr/include/c++/14/bits/stl_pair.h:946:9: error: no type named 'type' in 'struct std::enable_if<false, std::pair<int, std::pair<int, int> >&>'
  946 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:957:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U2 = _U1; _T1 = int; _T2 = std::pair<int, int>]'
  957 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:957:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h: In substitution of 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<int&, _U1&&>, std::is_assignable<std::pair<int, int>&, _U2&&> >::value, std::pair<int, std::pair<int, int> >&>::type std::pair<int, std::pair<int, int> >::operator=(std::pair<_T1, _T2>&&) [with _U1 = int; _U2 = int]':
a.cc:68:17:   required from here
   68 |                 a[p].mn=MP(0,l);
      |                               ^
/usr/include/c++/14/bits/stl_pair.h:957:9: error: no type named 'type' in 'struct std::enable_if<false, std::pair<int, std::pair<int, int> >&>'
  957 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:921:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&>) [with _T1 = int; _T2 = std::pair<int, int>; std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&> = const std::pair<int, std::pair<int, int> >&]'
  921 |       operator=(__conditional_t<__and_<is