Language: C++

#include <bits/stdc++.h>
#define X first
#define Y second
#define PB pop_back
#define LL long long
#define pii pair<LL,LL>
#define MEM(x,y) memset(x,y,sizeof(x))
#define bug(x) cout<<"debug "#x" is "<<x<<endl;
#define FIO ios::sync_with_stdio(false);
#define ALL(x) x.begin(),x.end()
#define LOG 25
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1|1)
#define vi vector<long long>

using namespace std;
typedef long long ll;
const ll mod=1e9;
const ll inf = 1e18+7;
const int maxn = 3e6+7;
int n,num_edge,a[N],f[N],ans[N],head[N];
struct Edge
{
	int to;
	int Next;
}edge[maxn];
void add_edge(int from,int to){
	edge[++num_edge].to=to;
	edge[num_edge].Next=head[from];
	head[from]=num_edge;
}
void dfs(int x,int fa){
	int last;
	int l=1,r=ans[fa];
	if(fa==0)
	{
		f[1]=a[x];
		ans[1]=1;
	}
	else
	{
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(a[x]<=f[mid])
				r=mid-1;
			else
				l=mid+1;
		}
		last=f[l];
		f[l]=a[x];
		ans[x]=ans[fa];
		if(l>ans[fa])
			ans[x]++;
	}
	for(int i=head[x];i;i=edge[i].Next)
	{
		int y=edge[i].to;
		if(y!=fa)
			dfs(y,x);
	}
	f[l] = last;
}
int main(){
    FIO
    int x,y;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n-1;i++){
		cin>>x>>y;
		add_edge(x,y);
		add_edge(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
	return 0;
}
/**
5
6
7
1 2 2 4
2 4 3 3
3 4 2 4
1 3 4 1
4 6 2 1
3 5 2 0
5 4 3 2
**/


Compiler output:
a.cc:21:18: error: 'N' was not declared in this scope
   21 | int n,num_edge,a[N],f[N],ans[N],head[N];
      |                  ^
a.cc:21:23: error: 'N' was not declared in this scope
   21 | int n,num_edge,a[N],f[N],ans[N],head[N];
      |                       ^
a.cc:21:30: error: 'N' was not declared in this scope
   21 | int n,num_edge,a[N],f[N],ans[N],head[N];
      |                              ^
a.cc:21:38: error: 'N' was not declared in this scope
   21 | int n,num_edge,a[N],f[N],ans[N],head[N];
      |                                      ^
a.cc: In function 'void add_edge(int, int)':
a.cc:29:29: error: 'head' was not declared in this scope; did you mean 'read'?
   29 |         edge[num_edge].Next=head[from];
      |                             ^~~~
      |                             read
a.cc: In function 'void dfs(int, int)':
a.cc:34:19: error: 'ans' was not declared in this scope; did you mean 'abs'?
   34 |         int l=1,r=ans[fa];
      |                   ^~~
      |                   abs
a.cc:37:17: error: 'f' was not declared in this scope
   37 |                 f[1]=a[x];
      |                 ^
a.cc:37:22: error: 'a' was not declared in this scope
   37 |                 f[1]=a[x];
      |                      ^
a.cc:45:28: error: 'a' was not declared in this scope
   45 |                         if(a[x]<=f[mid])
      |                            ^
a.cc:45:34: error: 'f' was not declared in this scope
   45 |                         if(a[x]<=f[mid])
      |                                  ^
a.cc:50:22: error: 'f' was not declared in this scope
   50 |                 last=f[l];
      |                      ^
a.cc:51:22: error: 'a' was not declared in this scope
   51 |                 f[l]=a[x];
      |                      ^
a.cc:56:19: error: 'head' was not declared in this scope; did you mean 'read'?
   56 |         for(int i=head[x];i;i=edge[i].Next)
      |                   ^~~~
      |                   read
a.cc:62:9: error: 'f' was not declared in this scope
   62 |         f[l] = last;
      |         ^
a.cc: In function 'int main()':
a.cc:68:36: error: 'a' was not declared in this scope
   68 |         for(int i=1;i<=n;i++) cin>>a[i];
      |                                    ^
a.cc:75:37: error: 'ans' was not declared in this scope; did you mean 'abs'?
   75 |         for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
      |                                     ^~~
      |                                     abs