Language: C++

#include<bits/stdc++.h>
#define in inline
#define re register
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9') {
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
int n,m,rt[200002],head[200002],a[200002],ls[20000002],rs[20000002],ans[200002],u,v,cnt,tot,s[20000002],la,r[200002],val[20000002];
struct edge{
	int to,next;
}e[400002];
inline void bu(re int x,re int y){
	e[++tot].to=y;
	e[tot].next=head[x];
	head[x]=tot;
}
inline int insert(re int v,re int l,re int r,re int x,re int vv) {
	int y=++cnt;
	s[y]=s[x]+1;val[y]=max(val[x],vv);
	if(l==r){
	val[y]=max(val[y],vv);
	return y;}
	ls[y]=ls[x];
	rs[y]=rs[x];
	int mid=(l+r)>>1;
	if(v<=mid)ls[y]=insert(v,l,mid,ls[x],vv);
	else rs[y]=insert(v,mid+1,r,rs[x],vv);
	return y;
}
inline int find(re int p,re int l,re int r,re int x){
	if(!p)return 0;
	if(r<=x)return val[p];
	re int mid=l+r>>1;
	if(x>mid)return max(find(ls[p],l,mid,x),find(rs[p],mid+1,r,x));
	else return find(ls[p],l,mid,x);
}
inline void dfs(re int x,re int y){
	ans[x]=max(ans[fa[x]],find(rt[y],1,1e9+1,a[x]));
	rt[x]=insert(a[x]+1,1,1e9+1,rt[y],ans[x]+1);
	for(re int i=head[x];i;i=e[i].next)
		if(e[i].to!=y)dfs(e[i].to,x);
}
int main(){
	n=read();
	for(re int i=1;i<=n;++i)a[i]=read();
	for(re int i=1;i<n;++i){
		u=read();
		v=read();
		bu(u,v);
		bu(v,u);
	}
	dfs(1,1);
	for(re int i=1;i<=n;++i)printf("%d\n",ans[i]+1);
}

Compiler output:
a.cc: In function 'int read()':
a.cc:6:16: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    6 |         re int t=0;
      |                ^
a.cc:7:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    7 |         re char v=getchar();
      |                 ^
a.cc: At global scope:
a.cc:19:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 | inline void bu(re int x,re int y){
      |                       ^
a.cc:19:32: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 | inline void bu(re int x,re int y){
      |                                ^
a.cc:24:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   24 | inline int insert(re int v,re int l,re int r,re int x,re int vv) {
      |                          ^
a.cc:24:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   24 | inline int insert(re int v,re int l,re int r,re int x,re int vv) {
      |                                   ^
a.cc:24:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   24 | inline int insert(re int v,re int l,re int r,re int x,re int vv) {
      |                                            ^
a.cc:24:53: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   24 | inline int insert(re int v,re int l,re int r,re int x,re int vv) {
      |                                                     ^
a.cc:24:62: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   24 | inline int insert(re int v,re int l,re int r,re int x,re int vv) {
      |                                                              ^~
a.cc:37:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 | inline int find(re int p,re int l,re int r,re int x){
      |                        ^
a.cc:37:33: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 | inline int find(re int p,re int l,re int r,re int x){
      |                                 ^
a.cc:37:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 | inline int find(re int p,re int l,re int r,re int x){
      |                                          ^
a.cc:37:51: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 | inline int find(re int p,re int l,re int r,re int x){
      |                                                   ^
a.cc: In function 'int find(int, int, int, int)':
a.cc:40:16: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   40 |         re int mid=l+r>>1;
      |                ^~~
a.cc: At global scope:
a.cc:44:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   44 | inline void dfs(re int x,re int y){
      |                        ^
a.cc:44:33: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   44 | inline void dfs(re int x,re int y){
      |                                 ^
a.cc: In function 'void dfs(int, int)':
a.cc:45:24: error: 'fa' was not declared in this scope; did you mean 'la'?
   45 |         ans[x]=max(ans[fa[x]],find(rt[y],1,1e9+1,a[x]));
      |                        ^~
      |                        la
a.cc:47:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   47 |         for(re int i=head[x];i;i=e[i].next)
      |                    ^
a.cc: In function 'int main()':
a.cc:52:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   52 |         for(re int i=1;i<=n;++i)a[i]=read();
      |                    ^
a.cc:53:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   53 |         for(re int i=1;i<n;++i){
      |                    ^
a.cc:60:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   60 |         for(re int i=1;i<=n;++i)printf("%d\n",ans[i]+1);
      |                    ^