Language: C++

#include <bits/stdc++.h>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vi g[200010];
vl a, l;
vl dp;

void dfs(int v, int p=-1){
    int pos = lower_bound(all(dp), a[v]) - dp.begin();
    ll tmp = dp[pos];
    dp[pos] = a[v];
    l[v] = lower_bound(all(dp), INFL) - dp.begin();
    for(auto u : g[v]){
        if(u == p) continue;
        dfs(u, v);
    }
    dp[pos] = tmp;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    a = vl(n);
    l = vl(n, 0);
    rep(i,n) cin >> a[i];
    rep(i,n-1){
        int u, v; cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dp = vl(n+1, INFL);
    dfs(0);
    rep(i,n) cout << l[i] << endl;
    return 0;
}#include <bits/stdc++.h>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vi g[200010];
vl a, l;
vl dp;

void dfs(int v, int p=-1){
    int pos = lower_bound(all(dp), a[v]) - dp.begin();
    ll tmp = dp[pos];
    dp[pos] = a[v];
    l[v] = lower_bound(all(dp), INFL) - dp.begin();
    for(auto u : g[v]){
        if(u == p) continue;
        dfs(u, v);
    }
    dp[pos] = tmp;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    a = vl(n);
    l = vl(n, 0);
    rep(i,n) cin >> a[i];
    rep(i,n-1){
        int u, v; cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dp = vl(n+1, INFL);
    dfs(0);
    rep(i,n) cout << l[i] << endl;
    return 0;
}

Compiler output:
a.cc:83:2: error: stray '#' in program
   83 | }#include <bits/stdc++.h>
      |  ^
a.cc:83:3: error: 'include' does not name a type
   83 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:97:8: error: redefinition of 'template<class T> std::string join(const std::vector<_Tp>&, std::string)'
   97 | string join(const vector<T>&v, string del=", "){ stringstream s;
      |        ^~~~
a.cc:15:8: note: 'template<class T> std::string join(const std::vector<_Tp>&, std::string)' previously declared here
   15 | string join(const vector<T>&v, string del=", "){ stringstream s;
      |        ^~~~
a.cc:101:10: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)'
  101 | ostream& operator<<(ostream& o, const vector<T>&v){
      |          ^~~~~~~~
a.cc:19:10: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here
   19 | ostream& operator<<(ostream& o, const vector<T>&v){
      |          ^~~~~~~~
a.cc:105:10: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<std::vector<_Tp> >&)'
  105 | ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
      |          ^~~~~~~~
a.cc:23:10: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<std::vector<_Tp> >&)' previously declared here
   23 | ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
      |          ^~~~~~~~
a.cc:110:13: error: redefinition of 'void _debug()'
  110 | inline void _debug(){cerr<<endl;}
      |             ^~~~~~
a.cc:28:13: note: 'void _debug()' previously defined here
   28 | inline void _debug(){cerr<<endl;}
      |             ^~~~~~
a.cc:112:6: error: redefinition of 'template<class First, class ... Rest> void _debug(const First&, const Rest& ...)'
  112 | void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}
      |      ^~~~~~
a.cc:30:6: note: 'template<class First, class ... Rest> void _debug(const First&, const Rest& ...)' previously declared here
   30 | void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}
      |      ^~~~~~
a.cc:122:14: error: redefinition of 'const double PI'
  122 | const double PI = (1*acos(0.0));
      |              ^~
a.cc:40:14: note: 'const double PI' previously defined here
   40 | const double PI = (1*acos(0.0));
      |              ^~
a.cc:123:14: error: redefinition of 'const double EPS'
  123 | const double EPS = 1e-9;
      |              ^~~
a.cc:41:14: note: 'const double EPS' previously defined here
   41 | const double EPS = 1e-9;
      |              ^~~
a.cc:124:11: error: redefinition of 'const int INF'
  124 | const int INF = 0x3f3f3f3f;
      |           ^~~
a.cc:42:11: note: 'const int INF' previously defined here
   42 | const int INF = 0x3f3f3f3f;
      |           ^~~
a.cc:125:10: error: redefinition of 'const ll INFL'
  125 | const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
      |          ^~~~
a.cc:43:10: note: 'const ll INFL' previously defined here
   43 | const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
      |          ^~~~
a.cc:126:10: error: redefinition of 'const ll mod'
  126 | const ll mod = 1e9 + 7;
      |          ^~~
a.cc:44:10: note: 'const ll mod' previously defined here
   44 | const ll mod = 1e9 + 7;
      |          ^~~
a.cc:128:13: error: redefinition of 'void finput(std::string)'
  128 | inline void finput(string filename) {
      |             ^~~~~~
a.cc:46:13: note: 'void finput(std::string)' previously defined here
   46 | inline void finput(string filename) {
      |             ^~~~~~
a.cc:132:4: error: redefinition of 'vi g [200010]'
  132 | vi g[200010];
      |    ^
a.cc:50:4: note: 'vi g [200010]' previously declared here
   50 | vi g[200010];
      |    ^
a.cc:133:4: error: redefinition of 'vl a'
  133 | vl a, l;
      |    ^
a.cc:51:4: note: 'vl a' previously declared here
   51 | vl a, l;
      |    ^
a.cc:133:7: error: redefinition of 'vl l'
  133 | vl a, l;
      |       ^
a.cc:51:7: note: 'vl l' previously declared here
   51 | vl a, l;
      |       ^
a.cc:134:4: error: redefinition of 'vl dp'
  134 | vl dp;
      |    ^~
a.cc:52:4: note: 'vl dp' previously declared here
   52 | vl dp;
      |    ^~
a.cc:136:6: error: redefinition of 'void dfs(int, int)'
  136 | void dfs(int v, int p=-1){
      |      ^~~
a.cc:54:6: note: 'void dfs(int, int)' previously defined here
   54 | void dfs(int v, int p=-1){
      |      ^~~
a.cc:148:5: error: redefinition of 'int main()'
  148 | int main(){
      |     ^~~~
a.cc:66:5: note: 'int main()' previously defined here
   66 | int main(){
      |     ^~~~